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

URLConnection.getInputStream returns unexpected NullPointerException for an invalid HTTP URL

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6u24
    • core-libs
    • x86
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
      Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7600]

      A DESCRIPTION OF THE PROBLEM :
      sun.net.www.protocol.http.HttpURLConnection.getInputStream throws nullpointer for non-uri url's. Duplicate of bug 6536522 which is closed with no fix

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      execute the following snippet:

      public static void main(String[] args) throws MalformedURLException, IOException {
      new URL("http:afdbakaka").openConnection().getInputStream();
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      IOException is thrown
      ACTUAL -
      NullPointerException is thrown

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NullPointerException
      at sun.net.www.ParseUtil.toURI(ParseUtil.java:261)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:910)
      at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:841)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1177)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public static void main(String[] args) throws MalformedURLException, IOException {
      new URL("http:afdbakaka").openConnection().getInputStream();
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Catching the nullpoinerexception as an indication the url is non-uri compliant can be a possible workaround, but it is ugly and not feasible in true production code. Also such a workaround makes the client code dependent on the bug in the sun.www. implementation.

            khazra Kurchi Subhra Hazra
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: