title: HttpURLConnection failes with NullPointerException on Lollipop
body: <p>I noticed that sometimes, not sure in which conditions, while downloading an image using Universal-Image-Loader (<a href="https://github.com/nostra13/Android-Universal-Image-Loader" rel="nofollow">https://github.com/nostra13/Android-Universal-Image-Loader</a>), I get the following NullPointerException:</p>
  
  <pre><code>E/ImageLoader(27386): Attempt to invoke virtual method 'boolean java.lang.String.startsWith(java.lang.String)' on a null object reference
  E/ImageLoader(27386): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.startsWith(java.lang.String)' on a null object reference
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.StatusLine.&lt;init&gt;(StatusLine.java:24)
  E/ImageLoader(27386):   at com.android.okhttp.Response$Builder.statusLine(Response.java:419)
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.JavaApiConverter.createOkResponse(JavaApiConverter.java:116)
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.ResponseCacheAdapter.get(ResponseCacheAdapter.java:53)
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:269)
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323)
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:491)
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
  E/ImageLoader(27386):   at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
  E/ImageLoader(27386):   at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromNetwork(BaseImageDownloader.java:113)
  E/ImageLoader(27386):   at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:84)
  E/ImageLoader(27386):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.downloadImage(LoadAndDisplayImageTask.java:290)
  E/ImageLoader(27386):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryCacheImageOnDisk(LoadAndDisplayImageTask.java:273)
  E/ImageLoader(27386):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:229)
  E/ImageLoader(27386):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:135)
  E/ImageLoader(27386):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  E/ImageLoader(27386):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  E/ImageLoader(27386):   at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p>This seems like a bug in <strong>okhttp</strong>, not in Universal-Image-Loader. The code does something like this, and it crashes in the call to <em>getResponseCode</em>:</p>
  
  <pre><code>String encodedUrl = Uri.encode(url, ALLOWED_URI_CHARS);
  HttpURLConnection conn = (HttpURLConnection) new URL(encodedUrl).openConnection();
  conn.getResponseCode()
  </code></pre>
  
  <p>I managed to work around this by disabling cache on the connection before calling <em>getResponseCode</em>:</p>
  
  <pre><code>conn.setUseCaches(false);
  </code></pre>
  
  <p>Does anyone have an idea why this happens and in which exact conditions? Can this be something related to server settings, perhaps something to do with caching?</p>