okhttpadcolonyhelpshift

OkHttp android 5 crash adcolony and helpshift


on android 5 only, some 3rd party sdks (adcolony and helpshift) crashes randomly (most of the time when app just started). On android 5 below, both works fine.

Both of them crashes on

com.android.okhttp.internal.http.JavaApiConverter.extractStatusLine(JavaApiConverter.java:329) com.android.okhttp.internal.http.JavaApiConverter.extractStatusLine(JavaApiConverter.java:324)

Helpshift crash stacktrace:

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference com.android.okhttp.internal.http.JavaApiConverter.extractStatusLine(JavaApiConverter.java:329) com.android.okhttp.internal.http.JavaApiConverter.extractStatusLine(JavaApiConverter.java:324) com.android.okhttp.internal.http.JavaApiConverter.createOkResponse(JavaApiConverter.java:116) com.android.okhttp.internal.http.ResponseCacheAdapter.get(ResponseCacheAdapter.java:53) com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:190) com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373) com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323) com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:491) com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105) com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25) com.helpshift.support.HSApiClient$1.run(HSApiClient.java:318) java.lang.Thread.run(Thread.java:818)

Ad colony crash stack trace:

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference com.android.okhttp.internal.http.JavaApiConverter.extractStatusLine(JavaApiConverter.java:329) com.android.okhttp.internal.http.JavaApiConverter.extractStatusLine(JavaApiConverter.java:324) com.android.okhttp.internal.http.JavaApiConverter.createOkResponse(JavaApiConverter.java:116) com.android.okhttp.internal.http.ResponseCacheAdapter.get(ResponseCacheAdapter.java:53) com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:269) com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373) com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106) com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:208) com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218) com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25) com.jirbo.adcolony.ADCDownload.run(SourceFile:107) at java.lang.Thread.run(Thread.java:818)

Anyone knows how to fix this?


Solution

  • The NPE you mentioned seems to be a similar one reported at okhttp issue thread for android 5.0: http://code.google.com/p/android/issues/detail?id=160522

    Probable reason for this Issue :
    You might be using a custom ResponseCache/third party ResponseCache and it is not implemented properly, and okhttp not handling null responses correctly.

    1. If you don't need Response caching

    The quick fix for this NPE is - Disabling cache on the connection by
    conn.setUseCaches(false)

    2. In case you need Response caching

    What implementation of ResponseCache you're using? Is it the Android one from android.net.http.HttpResponseCache, or a third-party one?

    Root cause for custom ResponseCache issue

    The root cause is that Android assumes that the status line (e.g. the part of the response that indicates the response code, a message) is held as the header with a null key. This is alluded to in the API docs when you look at the header with the index of zero, but is not explicit in the methods that return the Map, or that take a String

    See here: http://developer.android.com/reference/java/net/CacheResponse.html#getHeaders()

    From the stacktrace you provided it looks like the issue is related to using custom ResponseCache. If so, you can disable cache if not needed else you can contact the maintainers of custom response cache as mentioned in the response for okhttp issue given above.

    For any other Helpshift related queries, feel free to contact us at support@helpshift.com