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

URLConnection.openConnection NPE if ProxySelector.setDefault is set to null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 5.0
    • core-libs
    • beta
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If ProxySelector is set to null then it appears that no effort is made to get an http connection in HttpURLConnection.plainConnect(...). This results in a null pointer exception when the method attempts to get the http outputstream.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See attached source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      make a direct connection when ProxySelector = null
      ACTUAL -
      Null Pointer Exception

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.NullPointerException
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:773)
      at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:661)
      at HTTPTest.main(HTTPTest.java:15)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.net.ProxySelector;
      import java.net.URLConnection;
      import java.net.URL;

      public class HTTPTest {
      public static void main(String[] args) throws Exception {
      ProxySelector.setDefault(null);

      String url = "http://java.sun.com/";
      URL location = new URL(url);
      URLConnection con = null;
      con = location.openConnection();
      try {
      con.connect();
      } catch (NullPointerException ex) {
      ex.printStackTrace();
      }
      }
      }
      ---------- END SOURCE ----------
      ###@###.### 2005-1-10 23:40:19 GMT

            jccollet Jean-Christophe Collet (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: