Project: titanium
Issue TIMOB-18887: Android: Wrong implementation of TiResponseCache may cause occasional crashes in Lollipop
I was getting occasional crashes in my titanium module when downloading files using HttpUrlConnection on a Lollipop device. Tracing this to okhttp (the http client used in android 5), I posted a bug report (see: https://code.google.com/p/android/issues/detail?id=160522) There is a bug in okhttp where they don't handle null pointer correctly, which is returned from TiCacheResponse.getHeaders() or its null key's value, but the fact is that it shouldn't return null in the first place. This all comes from the way the cached header's multimap assumes that the status is in the null key at position 0 (see: http://developer.android.com/reference/java/net/URLConnection.html#getHeaderFields%28%29) For a full explanation of the cause see: https://code.google.com/p/android/issues/detail?id=160522#c5 Partial stack dump of the problem: {quote} Attempt to invoke virtual method 'boolean java.lang.String.startsWith(java.lang.String)' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.startsWith(java.lang.String)' on a null object reference at com.android.okhttp.internal.http.StatusLine.(StatusLine.java:24) at com.android.okhttp.Response$Builder.statusLine(Response.java:419) at com.android.okhttp.internal.http.JavaApiConverter.createOkResponse(JavaApiConverter.java:116) at com.android.okhttp.internal.http.ResponseCacheAdapter.get(ResponseCacheAdapter.java:53) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:269) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:491) at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105) at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25) {quote}
Story points: 5