From c58a1103b66cc25add92fd9e636e2718a2e93b69 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 15 Jun 2015 19:03:41 -0700 Subject: [PATCH] Fix NPE for trying to add metadata to error when it was nil --- src/objective-c/GRPCClient/GRPCCall.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 279ef935d50..d92a9d1b377 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -319,9 +319,12 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey"; if (strongSelf) { [strongSelf->_responseMetadata addEntriesFromDictionary:trailers]; - NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:error.userInfo]; - userInfo[kGRPCStatusMetadataKey] = strongSelf->_responseMetadata; - error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; + if (error) { + NSMutableDictionary *userInfo = + [NSMutableDictionary dictionaryWithDictionary:error.userInfo]; + userInfo[kGRPCStatusMetadataKey] = strongSelf->_responseMetadata; + error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; + } [strongSelf finishWithError:error]; } }];