FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 2.4.20-8 #1 Thu Mar 13 17:18:24 EST 2003 i686 athlon i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The BNF found in RFC 1738 shows that the path portion of a file URL cannot be empty - it must at least contain the forward slash ('/'). From Section 5 (BNF for specific URL schemes):
fileurl = "file://" [ host | "localhost" ] "/" fpath
The parseURL method in sun.net.www.protocol.file.Handler class does not check for this and allows file URLs without the slash to pass through without error.
For instance, the URL "file://" is not legal but is accepted anyways by the parseURL method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See source code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect a MalformedURLException to be thrown.
The documentation for URL#URL(URL, String) only refers to RFC 2396 but I would still expect the parsing to conform to the supporting RFCs. Especially since the job of parsing a the file specification is handed off to a specialized class. The Handler class should know what is required for a proper file URL specification.
ACTUAL -
file:
Protocol: (file)
Host: ()
Port: (-1)
Path: ()
file://192.168.3.164
Protocol: (file)
Host: (192.168.3.164)
Port: (-1)
Path: ()
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.net.*;
public class Main {
public static void main(String[] args) {
URL[] urls = null;
try {
urls = new URL[] {new URL("file://"),
new URL("file://192.168.3.164")};
} catch (MalformedURLException e) {
System.out.println("Malformed URL");
}
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
System.out.println("\n"+url.toExternalForm());
System.out.println("\tProtocol: (" + url.getProtocol() + ")");
System.out.println("\tHost: (" + url.getHost() + ")");
System.out.println("\tPort: (" + url.getPort() + ")");
System.out.println("\tPath: (" + url.getPath() + ")");
}
} // main
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Check for the slash prior to calling the any method that parses a file URL.
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 2.4.20-8 #1 Thu Mar 13 17:18:24 EST 2003 i686 athlon i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The BNF found in RFC 1738 shows that the path portion of a file URL cannot be empty - it must at least contain the forward slash ('/'). From Section 5 (BNF for specific URL schemes):
fileurl = "file://" [ host | "localhost" ] "/" fpath
The parseURL method in sun.net.www.protocol.file.Handler class does not check for this and allows file URLs without the slash to pass through without error.
For instance, the URL "file://" is not legal but is accepted anyways by the parseURL method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See source code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect a MalformedURLException to be thrown.
The documentation for URL#URL(URL, String) only refers to RFC 2396 but I would still expect the parsing to conform to the supporting RFCs. Especially since the job of parsing a the file specification is handed off to a specialized class. The Handler class should know what is required for a proper file URL specification.
ACTUAL -
file:
Protocol: (file)
Host: ()
Port: (-1)
Path: ()
file://192.168.3.164
Protocol: (file)
Host: (192.168.3.164)
Port: (-1)
Path: ()
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.net.*;
public class Main {
public static void main(String[] args) {
URL[] urls = null;
try {
urls = new URL[] {new URL("file://"),
new URL("file://192.168.3.164")};
} catch (MalformedURLException e) {
System.out.println("Malformed URL");
}
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
System.out.println("\n"+url.toExternalForm());
System.out.println("\tProtocol: (" + url.getProtocol() + ")");
System.out.println("\tHost: (" + url.getHost() + ")");
System.out.println("\tPort: (" + url.getPort() + ")");
System.out.println("\tPath: (" + url.getPath() + ")");
}
} // main
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Check for the slash prior to calling the any method that parses a file URL.
- relates to
-
JDK-6345395 java.net.URI: Valid URI isn't recognized
-
- Resolved
-