Index: core/bootstrap/src/org/netbeans/JarClassLoader.java =================================================================== RCS file: /cvs/core/bootstrap/src/org/netbeans/JarClassLoader.java,v retrieving revision 1.2 diff -u -r1.2 JarClassLoader.java --- core/bootstrap/src/org/netbeans/JarClassLoader.java 2 Nov 2002 21:06:02 -0000 1.2 +++ core/bootstrap/src/org/netbeans/JarClassLoader.java 5 Nov 2002 21:05:49 -0000 @@ -7,7 +7,7 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ @@ -25,6 +25,8 @@ import java.security.cert.Certificate; import java.util.*; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; /** @@ -352,7 +354,7 @@ JarFile src; public JarSource(JarFile file) throws MalformedURLException { - super(new URL("file:" + file.getName())); + super(fileToURL(new File(file.getName()))); src = file; } @@ -374,7 +376,7 @@ if (ze != null) System.err.println("Loading " + name + " from " + src.getName()); // NOI18N } - return ze == null ? null : new URL("jar:file:" + src.getName() + "!/" + ze.getName()); // NOI18N + return ze == null ? null : new URL("jar:" + fileToURL(new File(src.getName())).toExternalForm() + "!/" + ze.getName()); // NOI18N } protected byte[] readClass(String name, String path) throws IOException { @@ -399,13 +401,13 @@ File dir; public DirSource(File file) throws MalformedURLException { - super(file.toURL()); + super(fileToURL(file)); dir = file; } protected URL doGetResource(String name) throws MalformedURLException { File resFile = new File(dir, name); - return resFile.exists() ? resFile.toURL() : null; + return resFile.exists() ? fileToURL(resFile) : null; } protected byte[] readClass(String name, String path) throws IOException { @@ -424,6 +426,27 @@ } + /** Convert a file to a URL as safely as possible. + * Under JDK 1.4, handle hash marks etc. + * Unfortunately it was decided not to fix the major bugs + * in the JDK 1.3 implementation, so a separate API is needed. + * @see #27330 + */ + private static URL fileToURL(File f) throws MalformedURLException { + if (!System.getProperty("java.specification.version").startsWith("1.3")) { // NOI18N + try { + Method m = File.class.getMethod("toURI", null); // NOI18N + Object o = m.invoke(f, null); + m = o.getClass().getMethod("toURL", null); // NOI18N + return (URL)m.invoke(o, null); + } catch (InvocationTargetException e) { + throw (MalformedURLException)e.getTargetException(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return f.toURL(); + } // // ErrorManager's methods Index: core/src/org/netbeans/core/modules/HelpHelper.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/modules/HelpHelper.java,v retrieving revision 1.3 diff -u -r1.3 HelpHelper.java --- core/src/org/netbeans/core/modules/HelpHelper.java 29 Jan 2002 11:15:51 -0000 1.3 +++ core/src/org/netbeans/core/modules/HelpHelper.java 5 Nov 2002 21:05:49 -0000 @@ -14,6 +14,8 @@ package org.netbeans.core.modules; import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.*; import org.xml.sax.*; @@ -152,7 +154,7 @@ File helpset = new File(dir, res.replace('/', File.separatorChar)); if (helpset.isFile()) { try { - return helpset.toURL(); + return fileToURL(helpset); } catch (MalformedURLException mfue) { ErrorManager.getDefault().notify(mfue); return null; @@ -162,6 +164,28 @@ } return null; } + /** Convert a file to a URL as safely as possible. + * Under JDK 1.4, handle hash marks etc. + * Unfortunately it was decided not to fix the major bugs + * in the JDK 1.3 implementation, so a separate API is needed. + * @see #27330 + */ + private static URL fileToURL(File f) throws MalformedURLException { + if (!System.getProperty("java.specification.version").startsWith("1.3")) { // NOI18N + try { + Method m = File.class.getMethod("toURI", null); // NOI18N + Object o = m.invoke(f, null); + m = o.getClass().getMethod("toURL", null); // NOI18N + return (URL)m.invoke(o, null); + } catch (InvocationTargetException e) { + throw (MalformedURLException)e.getTargetException(); + } catch (Exception e) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); + } + } + return f.toURL(); + } + /** Quick parser for helpsets. * Just does enough work to extract the home ID Index: core/src/org/netbeans/core/projects/ModuleLayeredFileSystem.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/projects/ModuleLayeredFileSystem.java,v retrieving revision 1.20 diff -u -r1.20 ModuleLayeredFileSystem.java --- core/src/org/netbeans/core/projects/ModuleLayeredFileSystem.java 16 Oct 2002 06:04:41 -0000 1.20 +++ core/src/org/netbeans/core/projects/ModuleLayeredFileSystem.java 5 Nov 2002 21:05:49 -0000 @@ -361,9 +361,7 @@ } hash = x; } - // XXX #20830: module URLs on Windows have illegal backslash; the URI constructor rejects it - //private static final boolean isJDK14 = Dependency.JAVA_SPEC.compareTo(new SpecificationVersion("1.4")) >= 0; // NOI18N - private static final boolean isJDK14 = false; + private static final boolean isJDK14 = Dependency.JAVA_SPEC.compareTo(new SpecificationVersion("1.4")) >= 0; // NOI18N private static File findFile(String u) throws IOException { if (u.startsWith("jar:") && u.lastIndexOf("!/") != -1) { // NOI18N u = u.substring(4, u.lastIndexOf("!/")); Index: core/src/org/netbeans/core/projects/cache/XMLLayerCacheManagerImpl.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/projects/cache/XMLLayerCacheManagerImpl.java,v retrieving revision 1.2 diff -u -r1.2 XMLLayerCacheManagerImpl.java --- core/src/org/netbeans/core/projects/cache/XMLLayerCacheManagerImpl.java 5 Sep 2002 07:05:30 -0000 1.2 +++ core/src/org/netbeans/core/projects/cache/XMLLayerCacheManagerImpl.java 5 Nov 2002 21:05:50 -0000 @@ -14,10 +14,14 @@ package org.netbeans.core.projects.cache; import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.MalformedURLException; import java.net.URL; import java.util.Iterator; import java.util.List; import java.util.zip.CRC32; +import org.openide.ErrorManager; import org.xml.sax.SAXException; @@ -58,7 +62,7 @@ public FileSystem createLoadedFileSystem() throws IOException { if (cacheFile.exists()) { try { - return new XMLFileSystem(cacheFile.toURL()); + return new XMLFileSystem(fileToURL(cacheFile)); } catch (SAXException saxe) { IOException ioe = new IOException(saxe.toString()); LayerCacheManager.err.annotate(ioe, saxe); @@ -71,7 +75,7 @@ public void load(FileSystem fs) throws IOException { try { - ((XMLFileSystem)fs).setXmlUrl(cacheFile.toURL()); + ((XMLFileSystem)fs).setXmlUrl(fileToURL(cacheFile)); } catch (Exception e) { IOException ioe = new IOException(e.toString()); LayerCacheManager.err.annotate(ioe, e); @@ -165,7 +169,7 @@ hex = "0" + hex; // NOI18N } File data = new File(datadir, "data_" + hex); // NOI18N - url = data.toURL().toString(); + url = fileToURL(data).toExternalForm(); if (!data.isFile()) { OutputStream os = new FileOutputStream(data); try { @@ -220,6 +224,28 @@ } return false; + } + + /** Convert a file to a URL as safely as possible. + * Under JDK 1.4, handle hash marks etc. + * Unfortunately it was decided not to fix the major bugs + * in the JDK 1.3 implementation, so a separate API is needed. + * @see #27330 + */ + private static URL fileToURL(File f) throws MalformedURLException { + if (!System.getProperty("java.specification.version").startsWith("1.3")) { // NOI18N + try { + Method m = File.class.getMethod("toURI", null); // NOI18N + Object o = m.invoke(f, null); + m = o.getClass().getMethod("toURL", null); // NOI18N + return (URL)m.invoke(o, null); + } catch (InvocationTargetException e) { + throw (MalformedURLException)e.getTargetException(); + } catch (Exception e) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); + } + } + return f.toURL(); } }