Skip to content

Commit

Permalink
[ObjC] Raise an exception for a nil message.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thomasvl committed Aug 16, 2024
1 parent c6964f6 commit 35bd2be
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions objectivec/GPBUnknownFields.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ - (instancetype)initFromMessage:(nonnull GPBMessage *)message {
self = [super init];
if (self) {
fields_ = [[NSMutableArray alloc] init];
// This shouldn't happen with the annotations, but just incase something claiming nonnull
// does return nil, block it.
if (!message) {
[self release];
[NSException raise:NSInvalidArgumentException format:@"Message cannot be nil"];
}
NSData *data = GPBMessageUnknownFieldsData(message);
if (data) {
GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data];
Expand Down

0 comments on commit 35bd2be

Please sign in to comment.