Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8366734

HttpURLConnection.connect throws NPE within EmptyProxySelector

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      When setting an empty list for select, connect throws NPE. Maybe internal variable not init correctly.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      using DIRECT for empty lists
      ACTUAL -
      java.lang.NullPointerException: Cannot invoke "sun.net.www.http.HttpClient.getOutputStream()" because "this.http" is null

      ---------- BEGIN SOURCE ----------
      import java.net.*;

      public class HttpURLConWithProxy {
          public static void main(String[] args) throws Exception {
              ProxySelector.setDefault(new EmptyProxySelector());
              
              URL url = new URL("http://localhost:80");
              HttpURLConnection conn = (HttpURLConnection) url.openConnection();
              conn.connect();
          }
      }

      class EmptyProxySelector extends ProxySelector {
          public java.util.List<Proxy> select(URI uri) {
              return java.util.Collections.emptyList();
          }
          
          public void connectFailed(URI uri, java.net.SocketAddress sa, java.io.IOException ioe) {
          }
      }
      ---------- END SOURCE ----------

            pmtavare Patricia Tavares
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: