title: How to resolve NullPointerException on HttpURLConnection?
body: <p>I am developing an Android application, using ExoPlayer for video playback, Glide for image display, and a download library for file download, and they all have NullPointerException related to HttpURLConnection, I'm sure the link used is available.</p>
  <p>The magic is, I just follow these library's The method described in the official documentation loads the data normally, and this error occurs from time to time, and the three libraries may not throw NullPointerException at the same time, and I don't even know how to reproduce this problem.</p>
  <p>This is the error thrown by ExoPlayer, which prevents the video from loading:</p>
  <pre><code>E/LoadTask: Unexpected exception loading stream
        java.lang.NullPointerException: wrapped.getHeaderField(key) must not be null
          at com.android.tools.appinspection.network.httpurl.TrackedHttpURLConnection.getHeaderField(TrackedHttpURLConnection.kt:317)
          at com.android.tools.appinspection.network.httpurl.HttpsURLConnectionWrapper.getHeaderField(HttpsURLConnectionWrapper.kt:182)
          at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.isCompressed(DefaultHttpDataSource.java:829)
          at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:413)
          at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84)
          at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1009)
          at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
          at java.lang.Thread.run(Thread.java:923)
  </code></pre>
  <p>The video playback part of the code is as follows:</p>
  <pre class="lang-kotlin prettyprint-override"><code>            val factory = ProgressiveMediaSource.Factory(
                  DefaultHttpDataSource.Factory()
              )
              val mediaSource = arrayListOf&lt;MediaSource&gt;(
                  factory.createMediaSource(MediaItem.fromUri(video.base_url)),
                  factory.createMediaSource(MediaItem.fromUri(audio.base_url))
              )
              val media = MergingMediaSource(true, *mediaSource.toTypedArray())
              ViewModel.getPlayer()?.let { player -&gt;
                  player.setMediaSource(media)
                  player.prepare()
              }
  </code></pre>
  <p>And this is the error thrown by Aria, which cause software to crash:</p>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: pool-5-thread-2
      Process: io.github.sgpublic.bilidownload, PID: 22400
      java.lang.NullPointerException: wrapped.getRequestProperty(field) must not be null
          at com.android.tools.appinspection.network.httpurl.TrackedHttpURLConnection.getRequestProperty(TrackedHttpURLConnection.kt:235)
          at com.android.tools.appinspection.network.httpurl.HttpsURLConnectionWrapper.getRequestProperty(HttpsURLConnectionWrapper.kt:274)
          at com.arialyy.aria.http.ConnectionHelp.setConnectParam(ConnectionHelp.java:146)
          at com.arialyy.aria.http.download.HttpDFileInfoTask.run(HttpDFileInfoTask.java:82)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
          at java.lang.Thread.run(Thread.java:923)
  </code></pre>
  <p>I have tried Invalidate and Restart, and even uninstalled and reinstalled Android Studio completely, but the problem still cannot be solved, so what is the problem?</p>