Skip to content

Commit 35bd2be

Browse files
committed
[ObjC] Raise an exception for a nil message.
The api is annotated that it isn't valid, but incase someone calling code isn't annotated correct and someone returns nil for another nonnull api, it could happen, so make it an explicit failure just to be safe. PiperOrigin-RevId: 662935009
1 parent c6964f6 commit 35bd2be

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

objectivec/GPBUnknownFields.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ - (instancetype)initFromMessage:(nonnull GPBMessage *)message {
197197
self = [super init];
198198
if (self) {
199199
fields_ = [[NSMutableArray alloc] init];
200+
// This shouldn't happen with the annotations, but just incase something claiming nonnull
201+
// does return nil, block it.
202+
if (!message) {
203+
[self release];
204+
[NSException raise:NSInvalidArgumentException format:@"Message cannot be nil"];
205+
}
200206
NSData *data = GPBMessageUnknownFieldsData(message);
201207
if (data) {
202208
GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data];

0 commit comments

Comments
 (0)