Skip to content

Commit

Permalink
fix: handle responses without content type (#101)
Browse files Browse the repository at this point in the history
This fixes NullPointerException when response doesn't have content type. Exception stack trace:

```
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String okhttp3.MediaType.toString()' on a null object reference
        at io.socket.engineio.client.transports.PollingXHR$Request.onLoad(PollingXHR.java:271)
        at io.socket.engineio.client.transports.PollingXHR$Request.access$700(PollingXHR.java:148)
        at io.socket.engineio.client.transports.PollingXHR$Request$1.onResponse(PollingXHR.java:232)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
```
  • Loading branch information
Jacek Mleczek authored and darrachequesne committed Dec 8, 2020
1 parent 5c65197 commit 6f065b7
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ private void onResponseHeaders(Map<String, List<String>> headers) {

private void onLoad() {
ResponseBody body = response.body();
String contentType = body.contentType().toString();
MediaType mediaType = body.contentType();

try {
if (BINARY_CONTENT_TYPE.equalsIgnoreCase(contentType)) {
if (mediaType != null && BINARY_CONTENT_TYPE.equalsIgnoreCase(mediaType.toString())) {
this.onData(body.bytes());
} else {
this.onData(body.string());
Expand Down

0 comments on commit 6f065b7

Please sign in to comment.