From 191db9034598d75ba44adf613999c807a1efe457 Mon Sep 17 00:00:00 2001 From: Pete Huitsing Date: Mon, 14 Nov 2016 19:29:52 -0800 Subject: [PATCH] Prevent null header value from raising exception Summary: In the wild, our app will occasionally crash with: ``` Fatal Exception: java.lang.NullPointerException value == null ``` The stack trace brings it back to `okhttp3.Headers$Builder.checkNameAndValue (Headers.java:316)`: ``` if (value == null) throw new NullPointerException("value == null"); ``` In the proposed fix, we simply continue the documented functionality of the `extractHeaders` method by returning "null" for invalid data. Closes https://github.com/facebook/react-native/pull/10861 Differential Revision: D4178624 Pulled By: ericvicenti fbshipit-source-id: 632e742196339639cb57ea47f9d0efbf04f090be --- .../com/facebook/react/modules/network/NetworkingModule.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java index ecbd087c5..bd3062bb0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java @@ -533,6 +533,9 @@ public final class NetworkingModule extends ReactContextBaseJavaModule { } String headerName = header.getString(0); String headerValue = header.getString(1); + if (headerName == null || headerValue == null) { + return null; + } headersBuilder.add(headerName, headerValue); } if (headersBuilder.get(USER_AGENT_HEADER_NAME) == null && mDefaultUserAgent != null) {