If a RuntimeException is thrown by URLStreamHandler.parseURL during a "new URL(...)" then Classpath lets the exception through. Suns JDK seems to catch RuntimeExceptions in the URL constructor and turn them into a MalformedURLException. This doesn't seems to be documented. So this is not bug but a difference from SUN based implemenations. Example code to test with: import java.net.*; class u extends URLStreamHandler { public static void main(String [] v) throws MalformedURLException { new URL(null, "blah://", new u()); } protected URLConnection openConnection(URL u) { return null; } protected void parseURL(URL url, String spec, int start, int end) { throw new RuntimeException(); } } With Sun JDK it generates: Exception in thread "main" java.net.MalformedURLException at java.net.URL.<init>(URL.java:571) at u.main(u.java:6) With Cacao it generates: Exception in thread "main" java.lang.RuntimeException at u.parseURL(u.java:14) at java.net.URL.<init>(URL.java:480) at u.main(u.java:6)
Thanks for the concise bug report. I turned it into a Mauve test case. Fix checked in.
Subject: Bug 28095 CVSROOT: /cvsroot/classpath Module name: classpath Changes by: Tom Tromey <tromey> 06/06/20 21:31:37 Modified files: . : ChangeLog java/net : URL.java Log message: PR classpath/28095: * java/net/URL.java (URL): Throw MalformedURLException if a RuntimeException is caught. Chain exceptions. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.7886&r2=1.7887 http://cvs.savannah.gnu.org/viewcvs/classpath/java/net/URL.java?cvsroot=classpath&r1=1.53&r2=1.54 Patches: Index: ChangeLog =================================================================== RCS file: /cvsroot/classpath/classpath/ChangeLog,v retrieving revision 1.7886 retrieving revision 1.7887 diff -u -b -r1.7886 -r1.7887 --- ChangeLog 20 Jun 2006 20:36:13 -0000 1.7886 +++ ChangeLog 20 Jun 2006 21:31:36 -0000 1.7887 @@ -1,3 +1,9 @@ +2006-06-20 Tom Tromey <tromey@redhat.com> + + PR classpath/28095: + * java/net/URL.java (URL): Throw MalformedURLException if a + RuntimeException is caught. Chain exceptions. + 2006-06-20 Lillian Angel <langel@redhat.com> * gnu/java/awt/peer/gtk/GtkCheckboxPeer.java Index: java/net/URL.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/net/URL.java,v retrieving revision 1.53 retrieving revision 1.54 diff -u -b -r1.53 -r1.54 --- java/net/URL.java 2 Mar 2006 00:25:21 -0000 1.53 +++ java/net/URL.java 20 Jun 2006 21:31:37 -0000 1.54 @@ -482,7 +482,17 @@ } catch (URLParseError e) { - throw new MalformedURLException(e.getMessage()); + MalformedURLException mue = new MalformedURLException(e.getMessage()); + mue.initCause(e); + throw mue; + } + catch (RuntimeException e) + { + // This isn't documented, but the JDK also catches + // RuntimeExceptions here. + MalformedURLException mue = new MalformedURLException(e.getMessage()); + mue.initCause(e); + throw mue; } if (hashAt >= 0)