Index: src/OFIntrospection.m ================================================================== --- src/OFIntrospection.m +++ src/OFIntrospection.m @@ -385,12 +385,15 @@ - (instancetype)of_initWithIvar: (Ivar)ivar { self = [super init]; @try { - _name = [[OFString alloc] - initWithUTF8String: ivar_getName(ivar)]; + const char *name = ivar_getName(ivar); + + if (name != NULL) + _name = [[OFString alloc] initWithUTF8String: + (const char *_Nonnull)ivar_getName(ivar)]; _typeEncoding = ivar_getTypeEncoding(ivar); _offset = ivar_getOffset(ivar); } @catch (id e) { [self release]; @throw e; Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -208,11 +208,11 @@ /*! * @brief Returns the superclass of the object. * * @return The superclass of the object */ -- (Class)superclass; +- (nullable Class)superclass; /*! * @brief Returns a boolean whether the object of the specified kind. * * @param class_ The class whose kind is checked @@ -505,11 +505,11 @@ /*! * @brief Returns the superclass of the class. * * @return The superclass of the class */ -+ (Class)superclass; ++ (nullable Class)superclass; /*! * @brief Checks whether instances of the class respond to a given selector. * * @param selector The selector which should be checked for respondence Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -352,20 +352,29 @@ } + (IMP)replaceClassMethod: (SEL)selector withMethodFromClass: (Class)class { + IMP method = [class methodForSelector: selector]; + + if (method == NULL) + @throw [OFInvalidArgumentException exception]; + return class_replaceMethod(object_getClass(self), selector, - [class methodForSelector: selector], + (IMP _Nonnull)method, typeEncodingForSelector(object_getClass(class), selector)); } + (IMP)replaceInstanceMethod: (SEL)selector withMethodFromClass: (Class)class { - return class_replaceMethod(self, selector, - [class instanceMethodForSelector: selector], + IMP method = [class instanceMethodForSelector: selector]; + + if (method == NULL) + @throw [OFInvalidArgumentException exception]; + + return class_replaceMethod(self, selector, (IMP _Nonnull)method, typeEncodingForSelector(class, selector)); } + (void)inheritMethodsFromClass: (Class)class { @@ -454,11 +463,11 @@ } @finally { free(methodList); } #endif - [self inheritMethodsFromClass: [class superclass]]; + [self inheritMethodsFromClass: superclass]; } + (BOOL)resolveClassMethod: (SEL)selector { return NO; @@ -474,11 +483,11 @@ return self; } - (Class)class { - return object_getClass(self); + return (Class _Nonnull)object_getClass(self); } - (Class)superclass { return class_getSuperclass(object_getClass(self)); Index: src/instance.m ================================================================== --- src/instance.m +++ src/instance.m @@ -55,11 +55,11 @@ id obj = (id)bytes; if (cls == Nil || bytes == NULL) return nil; - object_setClass(obj, cls); + object_setClass(obj, (Class _Nonnull)cls); if (!callConstructors(cls, obj)) return nil; return obj;