JDK-4496251 : URLStreamHandler Problems
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-08-24
  • Updated: 2001-09-26
  • Resolved: 2001-09-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 beta3Fixed
Related Reports
Relates :  
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: merlin-beta3 INTEGRATED IN: merlin-beta3
14-06-2004

WORK AROUND Name: nt126004 Date: 08/24/2001 Customer's Workaround: To find if a host was undefined, examine the authority first. If it is null, then the host is an undefined host even if it looks like an empty host. So is the port. Surround the host by '[' and ']' if the autorithy starts with '[' No easy work around for the empty port in IPV6. ======================================================================
11-06-2004

EVALUATION Will fix in Merlin. ###@###.### 2001-09-14
14-09-2001