# HG changeset patch # User dbuck # Date 1450728859 -3600 # Node ID 45c1293ab19ab060bdae934b9f51bd5280f9b492 # Parent 03b4e6dc367be8a90bc0cfbad47fcc8774d835cc# Parent 0c33c65fa8588437b51f7401b083ff608410b0b8 Merge diff -r 03b4e6dc367b -r 45c1293ab19a jdk/src/java.base/share/classes/java/net/URL.java --- a/jdk/src/java.base/share/classes/java/net/URL.java Mon Dec 21 20:54:00 2015 +0100 +++ b/jdk/src/java.base/share/classes/java/net/URL.java Mon Dec 21 21:14:19 2015 +0100 @@ -310,7 +310,8 @@ * @param host the name of the host. * @param port the port number on the host. * @param file the file on the host - * @exception MalformedURLException if an unknown protocol is specified. + * @exception MalformedURLException if an unknown protocol or the port + * is a negative number other than -1 * @see java.lang.System#getProperty(java.lang.String) * @see java.net.URL#setURLStreamHandlerFactory( * java.net.URLStreamHandlerFactory) @@ -329,9 +330,9 @@ * name, {@code host} name, and {@code file} name. The * default port for the specified protocol is used. *

- * This method is equivalent to calling the four-argument - * constructor with the arguments being {@code protocol}, - * {@code host}, {@code -1}, and {@code file}. + * This constructor is equivalent to the four-argument + * constructor with the only difference of using the + * default port for the specified protocol. * * No validation of the inputs is performed by this constructor. * @@ -372,7 +373,8 @@ * @param port the port number on the host. * @param file the file on the host * @param handler the stream handler for the URL. - * @exception MalformedURLException if an unknown protocol is specified. + * @exception MalformedURLException if an unknown protocol or the port + is a negative number other than -1 * @exception SecurityException * if a security manager exists and its * {@code checkPermission} method doesn't allow @@ -446,7 +448,9 @@ * * @param spec the {@code String} to parse as a URL. * @exception MalformedURLException if no protocol is specified, or an - * unknown protocol is found, or {@code spec} is {@code null}. + * unknown protocol is found, or {@code spec} is {@code null}, + * or the parsed URL fails to comply with the specific syntax + * of the associated protocol. * @see java.net.URL#URL(java.net.URL, java.lang.String) */ public URL(String spec) throws MalformedURLException { @@ -493,7 +497,9 @@ * @param context the context in which to parse the specification. * @param spec the {@code String} to parse as a URL. * @exception MalformedURLException if no protocol is specified, or an - * unknown protocol is found, or {@code spec} is {@code null}. + * unknown protocol is found, or {@code spec} is {@code null}, + * or the parsed URL fails to comply with the specific syntax + * of the associated protocol. * @see java.net.URL#URL(java.lang.String, java.lang.String, * int, java.lang.String) * @see java.net.URLStreamHandler @@ -513,7 +519,9 @@ * @param spec the {@code String} to parse as a URL. * @param handler the stream handler for the URL. * @exception MalformedURLException if no protocol is specified, or an - * unknown protocol is found, or {@code spec} is {@code null}. + * unknown protocol is found, or {@code spec} is {@code null}, + * or the parsed URL fails to comply with the specific syntax + * of the associated protocol. * @exception SecurityException * if a security manager exists and its * {@code checkPermission} method doesn't allow diff -r 03b4e6dc367b -r 45c1293ab19a jdk/test/java/net/URL/TestPort.java --- a/jdk/test/java/net/URL/TestPort.java Mon Dec 21 20:54:00 2015 +0100 +++ b/jdk/test/java/net/URL/TestPort.java Mon Dec 21 21:14:19 2015 +0100 @@ -23,28 +23,33 @@ /* * @test - * @bug 4101492 4444213 + * @bug 4101492 4444213 4906983 * @summary The java.net.URL constructor allows port < 0 and port > 65535 */ import java.net.*; public class TestPort { - public static void main(String[] args) { - URL url = null; + public static void main(String[] args) throws MalformedURLException { + // URLs are able to have port bigger than TCP-Port 65535 and + // to have no port (-1) at all.: + URL url = new URL("http","server",Integer.MAX_VALUE,"/path"); + url = new URL("http://server:"+Integer.MAX_VALUE+"/path"); + url = new URL("http://server/path"); + url = new URL("http","server",-1,"/path"); + try { url = new URL("ftp", "java.sun.com", -20, "/pub/"); + throw new RuntimeException("MalformedURLException not thrown!"); } catch (MalformedURLException e) { - url = null; + // Everything fine. MalformedURLException expected } - if (url != null) - throw new RuntimeException("MalformedURLException not thrown!"); + try { url = new URL("ftp://java.sun.com:-20/pub/"); + throw new RuntimeException("MalformedURLException not thrown!"); } catch (MalformedURLException e) { - url = null; + // Everything fine. MalformedURLException expected } - if (url != null) - throw new RuntimeException("MalformedURLException not thrown!"); } }