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

URLStreamHandler Problems

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta3
    • generic
    • generic



      Name: nt126004 Date: 08/24/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      Java 1.4 is definitively much better at URL parsing
      than 1.3. However, 1.4 beta still has a few nits...

      DESCRIPTION OF EXPECTED VERSUS ACTUAL RESULTS
      =============================================

      Undefined Hosts are not Empty Hosts
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      The absolute URL: "http:path" is parsed:
      Protocol: "http"
      Authority: (undefined)
        UserInfo: (undefined)
      Host: "" <=== NO. the host is undefined.
      Port: -1 <=== where -1 does not mean "default"
      Path: "path"
      Query: (undefined)
      Ref: (undefined)

      Compare with the absolute URL: http:///path, which does have
      an empty host.

      IPV6 references - incorrect host
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      The absolute URL: "http://[a:b:c]" is parsed:
      Protocol: "http"
      Authority: "[a:b:c]"
        UserInfo: (undefined)
      Host: "a:b:c" <=== NO. the host is "[a:b:c]".
      Port: -1
      Path: "path"
      Query: (undefined)
      Ref: (undefined)

      Because, according to RFC 2732:
            host = hostname | IPv4address | IPv6reference
            ipv6reference = "[" IPv6address "]"


      IPV6 references - empty port is allowed
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      The absolute URL "http://[a:b:c]:" is correct.
      but generates a java.net.MalformedURLException
      when parsed.

      It should parse:
      Protocol: "http"
      Authority: "[a:b:c]"
        UserInfo: (undefined)
      Host: "[a:b:c]"
      Port: -1
      Path: ""
      Query: (undefined)
      Ref: (undefined)

      Because, according to RFC 2396:
            hostport = host [ ":" port ]
            port = *digit


      EXACT STEPS TO REPRODUCE THE PROBLEM.
      =====================================

      Compile and run the following JAVA source.


      COMPLETE JAVA SOURCE CODE THAT DEMONSTRATES THE PROBLEM. (TEST PROGRAM)
      =======================================================================

      import java.net.*;

      class URLTest {
         public static void main(String[] arg) {
            String urls[] = {
               "http:path",
               "http://[a:b:c]",
               "http://[a:b:c]:"
            };
            for (int i=0; i < urls.length; ++i) {
               System.out.println("------------------ URL: " + urls[i]);
               try {
                  URL anURL = new URL(urls[i]);
                  showURL(anURL);
               }
               catch (MalformedURLException e) {
                  System.out.println("Malformed URI: " + e.getMessage());
               }
            }
         }

         public static void showURL(URL url) {
            System.out.println("Protocol: " + ((url.getProtocol() ==
      null)? "(undefined)" : ("\"" + url.getProtocol() + "\"")));
            System.out.println("Authority: " + ((url.getAuthority() ==
      null)? "(undefined)" : ("\"" + url.getAuthority() + "\"")));
            System.out.println("UserInfo: " + ((url.getUserInfo() ==
      null)? "(undefined)" : ("\"" + url.getUserInfo() + "\"")));
            System.out.println("Host: " + ((url.getHost() ==
      null)? "(undefined)" : ("\"" + url.getHost() + "\"")));
            System.out.println("Port: \"" + Integer.toString(url.getPort())
      + "\"");
            System.out.println("Path: " + ((url.getPath() ==
      null)? "(undefined)" : ("\"" + url.getPath() + "\"")));
            System.out.println("Query: " + ((url.getQuery() ==
      null)? "(undefined)" : ("\"" + url.getQuery() + "\"")));
            System.out.println("Ref: " + ((url.getRef() ==
      null)? "(undefined)" : ("\"" + url.getRef() + "\"")));
         }
      }

      PRODUCED OUTPUT.
      ================

      ------------------ URL: http:path
      Protocol: "http"
      Authority: (undefined)
        UserInfo: (undefined)
      Host: ""
      Port: "-1"
      Path: "path"
      Query: (undefined)
      Ref: (undefined)
      ------------------ URL: http://[a:b:c]
      Protocol: "http"
      Authority: "[a:b:c]"
        UserInfo: (undefined)
      Host: "a:b:c"
      Port: "-1"
      Path: ""
      Query: (undefined)
      Ref: (undefined)
      ------------------ URL: http://[a:b:c]:
      Malformed URI:


      ADDITIONAL CONFIGURATION INFORMATION.
      =====================================
      None.
      (Review ID: 130601)
      ======================================================================

            ywangsunw Yingxian Wang (Inactive)
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: