void
_object_set_associative_reference(id object, const void *key, id value, uintptr_t policy)
{
// This code used to work when nil was passed for object and key. Some code
// probably relies on that to not crash. Check and handle it explicitly.
// rdar://problem/44094390
if (!object && !value) return;
if (object->getIsa()->forbidsAssociatedObjects())
_objc_fatal("objc_setAssociatedObject called on instance (%p) of class %s which does not allow associated objects", object, object_getClassName(object));
...
I guess if (!object && !value) return; should be if (!object) return;
solution
check anObject is non nil before invoke objc_setAssociatedObject()
there is a crash when some stubed object has been release during one testcase
crash stack:
reason
when stubedObject has been release,
key()
at line 3 in KWClearAllObjectStubs() will return nilKWObjectClassRestored() invoke KWInterceptedObjectKey() with nil
objc_setAssociatedObject() will crash when anObject is nil, and key is not nil
according to https://opensource.apple.com/source/objc4/objc4-781/runtime/objc-references.mm
I guess
if (!object && !value) return;
should beif (!object) return;
solution
check
anObject
is non nil before invokeobjc_setAssociatedObject()