[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
diff --git a/objectivec/GPBUnknownFields.m b/objectivec/GPBUnknownFields.m
index 2672d10..87e62b9 100644
--- a/objectivec/GPBUnknownFields.m
+++ b/objectivec/GPBUnknownFields.m
@@ -197,6 +197,12 @@
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];