Chris: I made the documentation change: http://cr.openjdk.java.net/~jzavgren/4880778/webrev.03/
John ----- Original Message ----- From: chris.hega...@oracle.com To: john.zavg...@oracle.com Cc: net-dev@openjdk.java.net Sent: Monday, February 4, 2013 11:19:42 AM GMT -05:00 US/Canada Eastern Subject: Re: RFR JDK-4880778 Thanks John, Trivially, and unrelated to your changes but while you're there, I would really like to remove "are supposed to". < * Only classes derived from URLStreamHandler are supposed to be able < * to use this method to set the values of the URL fields. --- > * Only classes derived from URLStreamHandler are able to use this > * method to set the values of the URL fields. It is still not great, but I think the best we can do with an old API. -Chris. On 04/02/2013 14:00, John Zavgren wrote: > I posted a new webrev image: > http://cr.openjdk.java.net/~jzavgren/4880778/webrev.02/ > > I made two changes: > 1.) modified the indentation that's used for the argument list of the URL > class set() methods. > 2.) changed the documentation for the set method in the URLStreamHandler > class. > > > ----- Original Message ----- > From: john.zavg...@oracle.com > To: net-dev@openjdk.java.net > Sent: Saturday, February 2, 2013 9:47:31 AM GMT -05:00 US/Canada Eastern > Subject: RFR JDK-4880778 > > Greetings: > > Please consider the following modification of our classes for handling URLs. > > http://cr.openjdk.java.net/~jzavgren/4880778/webrev.01/ > > ---- background ---- > See http://java.sun.com/j2se/1.4.2/docs/api/java/net/URL.html. > The URL class is declared final yet has two protected methods: > > protected void set(String protocol, > String host, > int port, > String file, > String ref) > > protected void set(String protocol, > String host, > int port, > String authority, > String userInfo, > String path, > String query, > String ref) > > > Since the final class can't be subclassed these methods can't be accessed. > They could be package protected instead. (i.e. no access specifier) > -------------------- > Solution: > 1.) I made the set method in the URL class "package protected" > 2.) I edited the java doc documentation to eliminate reference to the set > method in the URL class from the URLStreamHandler class > > 3.) I wrote a test program (URLTest.java) (at the end of this message) that > attempts to call the set method from a URL object... > When there is no package statement: > > //package java.net; > > the compilation fails > java/net/URLTest.java:28: error: > set(String,String,int,String,String,String,String,String) is not public in > URL; cannot be accessed from outside package > myURL.set("ftp", "vpn.zavgren.com", 77, "lugnut.txt", "","","",""); > ^ > 1 error > 4.) When there is a package statement in the source code: > > package java.net; > > the code compiles but it creates a run time error. > jzavgren@ubuntuVM:~/code/java/URL$ java java.net.URLTest > Exception in thread "main" java.lang.SecurityException: Prohibited package > name: java.net > at java.lang.ClassLoader.preDefineClass(ClassLoader.java:651) > at java.lang.ClassLoader.defineClass(ClassLoader.java:785) > at > java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) > at java.net.URLClassLoader.defineClass(URLClassLoader.java:442) > at java.net.URLClassLoader.access$100(URLClassLoader.java:64) > at java.net.URLClassLoader$1.run(URLClassLoader.java:354) > at java.net.URLClassLoader$1.run(URLClassLoader.java:348) > at java.security.AccessController.doPrivileged(Native Method) > at java.net.URLClassLoader.findClass(URLClassLoader.java:347) > at java.lang.ClassLoader.loadClass(ClassLoader.java:423) > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) > at java.lang.ClassLoader.loadClass(ClassLoader.java:356) > at > sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:491) > ----- URLTest.java ----- > package java.net; > import java.net.*; > import java.io.*; > public class URLTest > { > public static void main (String[]args) > { > URL myURL=null; > try > { > myURL = new URL ("http", "www.zavgren.com", 80, "/index.html"); > } > catch (MalformedURLException mfue) > { > System.err.println (mfue); > } > System.out.printf ("The URL is: %s\n", myURL.toString ()); > System.out.printf ("The protocol is: %s\n", myURL.getProtocol()); > System.out.printf ("The external form is: %s\n", myURL.toExternalForm()); > System.out.printf ("Opening connection... \n"); > try > { > URLConnection uc = myURL.openConnection(); > } > catch (IOException io) > { > } > myURL.set("ftp", "vpn.zavgren.com", 77, "lugnut.txt", "","","",""); > } > }; > > ------------------------ > Thanks! > John