Open tarbayev opened 12 years ago
In method:
- (id)objectWithData:(NSData *)jsonData error:(NSError **)error { if(jsonData == NULL) { [NSException raise:NSInvalidArgumentException format:@"The jsonData argument is NULL."]; } return([self objectWithUTF8String:(const unsigned char *)[jsonData bytes] length:[jsonData length] error:error]); }
-[NSData bytes] returns nil, if the length of the receiver is 0.
This causes raising exception in:
- (id)objectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length error:(NSError **)error { if(parseState == NULL) { [NSException raise:NSInternalInconsistencyException format:@"parseState is NULL."]; } if(string == NULL) { [NSException raise:NSInvalidArgumentException format:@"The string argument is NULL."]; } return(_JKParseUTF8String(parseState, NO, string, (size_t)length, error)); }
According to Apple's recommendations, a good practice would be to return nil when string is equal to NULL in second method and raising no exception. This will make behavior more stable.
+1 for this solution
Whats doubly frustrating is if you pass in an NSError pointer an exception is still thrown instead of setting the NSError pointer and returning nil.
In method:
-[NSData bytes] returns nil, if the length of the receiver is 0.
This causes raising exception in:
According to Apple's recommendations, a good practice would be to return nil when string is equal to NULL in second method and raising no exception. This will make behavior more stable.