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
This commit is contained in:
Pete Huitsing 2016-11-14 19:29:52 -08:00 committed by Facebook Github Bot
parent 39c18186e1
commit 191db90345
1 changed files with 3 additions and 0 deletions

View File

@ -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) {