Name: yyC67448 Date: 12/29/97
The java.net.URL(String protocol, String host, int port, String file)
constructor allows null host parameter for http and ftp url's.
Here is the test demonstrating the bug:
------------------------ Test.java ---------------------------------------
import java.net.*;
public class Test
{
public static void main(String args[])
{
URL ftp_url = null;
URL http_url = null;
String host = null;
String file = "/index.html";
int port = -1;
try {
ftp_url = new URL("ftp", host, port, file);
http_url = new URL("http", host, port, file);
} catch(MalformedURLException e)
{
System.out.println("Passed. OKAY");
System.exit(0);
}
catch(Exception e)
{
System.out.println("Unexpected exception:" + e);
System.exit(-1);
}
System.out.println("No exceptions");
System.exit(-1);
}
}
------------------------- Output from the test ----------------------------
No exceptions
---------------------------------------------------------------------------
======================================================================
- duplicates
-
JDK-4218654 URL constructor throws NullPointer rather than MalformedURL if file is null
- Closed