This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch: URLClassLoader change
- From: Mark Wielaard <mark at klomp dot org>
- To: tromey at redhat dot com
- Cc: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 10 Dec 2002 21:07:38 +0100
- Subject: Re: Patch: URLClassLoader change
- Organization:
- References: <871y4qwxyz.fsf@fleche.redhat.com>
Hi,
On Tue, 2002-12-10 at 00:53, Tom Tromey wrote:
> The JDK uses absolute (actually canonical -- I tested) paths in its
> CodeSource objects. I think this makes sense; this is what the
> appended implements.
Thanks for doing the research. It certainly makes sense to do this.
> It is kind of ugly since baseURL can't be final
> any more.
But here you can do the 'use a static method in the super() call' trick.
(Insert rant about the stupid rule that the first statement of a
constructor must be a this() or super() call but that to be useful you
are still allowed to change the arguments, etc...)
I attached a slightly rewritten patch.
(Note that it compiles, but that is all testing that I done).
Thanks for cleaning up that last formatting issues in the file.
Cheers,
Mark
Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URLClassLoader.java,v
retrieving revision 1.11
diff -u -r1.11 URLClassLoader.java
--- java/net/URLClassLoader.java 8 Dec 2002 23:49:57 -0000 1.11
+++ java/net/URLClassLoader.java 10 Dec 2002 20:03:01 -0000
@@ -212,7 +212,7 @@
return null;
}
}
-
+
/**
* A <code>Resource</code> represents a resource in some
* <code>URLLoader</code>. It also contains all information (e.g.,
@@ -271,6 +271,23 @@
abstract InputStream getInputStream() throws IOException;
}
+ static URL getCanonicalFileURL(URL url)
+ {
+ URL result = url;
+ if ("file".equals(url.getProtocol()))
+ {
+ try
+ {
+ File f = new File(url.getFile()).getCanonicalFile();
+ url = new URL("file", "", f.toString());
+ }
+ catch (IOException ignore)
+ {
+ }
+ }
+ return result;
+ }
+
/**
* A <code>JarURLLoader</code> is a type of <code>URLLoader</code>
* only loading from jar url.
@@ -282,8 +299,8 @@
public JarURLLoader(URLClassLoader classloader, URL baseURL)
{
- super(classloader, baseURL);
-
+ super(classloader, getCanonicalFileURL(baseURL));
+
// cache url prefix for all resources in this jar url
String external = baseURL.toExternalForm();
StringBuffer sb = new StringBuffer(external.length() + 6);
@@ -306,7 +323,7 @@
this.baseJarURL = baseJarURL;
this.jarfile = jarfile;
}
-
+
/** get resource with the name "name" in the jar url */
Resource getResource(String name)
{
@@ -331,7 +348,6 @@
return null;
}
}
-
}
final static class JarURLResource extends Resource
@@ -358,7 +374,7 @@
{
return entry.getCertificates();
}
-
+
URL getURL()
{
try
@@ -368,7 +384,9 @@
}
catch(MalformedURLException e)
{
- throw new InternalError(e.toString());
+ InternalError ie = new InternalError();
+ ie.initCause(e);
+ throw ie;
}
}
}
@@ -468,19 +486,24 @@
FileURLLoader(URLClassLoader classloader, URL url)
{
- super(classloader, url);
- // Note that this must be a "file" protocol URL.
- dir = new File(url.getFile());
+ super(classloader, getCanonicalFileURL(url));
+ dir = new File(baseURL.getFile());
}
-
+
/** get resource with the name "name" in the file url */
Resource getResource(String name)
{
File file = new File(dir, name);
+ try
+ {
+ file = file.getCanonicalFile();
+ }
+ catch (IOException ignore)
+ {
+ }
if (file.exists() && !file.isDirectory())
return new FileResource(this, name, file);
- else
- return null;
+ return null;
}
}
@@ -503,7 +526,7 @@
{
return (int)file.length();
}
-
+
public URL getURL()
{
try
@@ -513,7 +536,9 @@
}
catch(MalformedURLException e)
{
- throw new InternalError(e.toString());
+ InternalError ie = new InternalError();
+ ie.initCause(e);
+ throw ie;
}
}
}
@@ -667,13 +692,12 @@
{
String file = newUrl.getFile();
// Check that it is not a directory
- if (!(file.endsWith("/") || file.endsWith(File.separator)))
+ if (! (file.endsWith("/") || file.endsWith(File.separator)))
loader = new JarURLLoader(this, newUrl);
- else // it's a url that point to a jar file
- if ("file".equals(newUrl.getProtocol()))
- loader = new FileURLLoader(this, newUrl);
- else
- loader = new RemoteURLLoader(this, newUrl);
+ else if ("file".equals(newUrl.getProtocol()))
+ loader = new FileURLLoader(this, newUrl);
+ else
+ loader = new RemoteURLLoader(this, newUrl);
// cache it
urlloaders.put(newUrl, loader);