[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
pull/17812/head
Thomas Van Lenten 4 months ago committed by Copybara-Service
parent 7a039dd177
commit d228777abd
  1. 6
      objectivec/GPBUnknownFields.m

@ -197,6 +197,12 @@ static BOOL MergeFromInputStream(GPBUnknownFields *self, GPBCodedInputStream *in
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];

Loading…
Cancel
Save