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>, Jeroen Frijters <jeroen at sumatra dot nl>
- Date: 29 Dec 2002 23:05:01 +0100
- Subject: Re: Patch: URLClassLoader change
- Organization:
- References: <871y4qwxyz.fsf@fleche.redhat.com> <1039550858.7431.34.camel@elsschot>
Hi,
On Tue, 2002-12-10 at 21:07, Mark Wielaard wrote:
> 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.
But it was a lot of trouble to get this right. See my previous patch for
directories. And for Windows based file systems it is a real hassle to
get it correct in all cases since file URLs use forward slashes but File
paths use backward slashes. Translating from URL to File and back is
nasty in that case.
I discussed this with Jeroen Frijters which has used the Classpath
libraries to get Eclipse running on dotNet.
<http://radio.weblogs.com/0109845/2002/12/28.html#a76>
And we agreed that taking all canonicalization out of URLClassLoader was
the best approach. (He also found the noCert bug). So I propose the
following patch (which supersedes my earlier one):
2002-12-28 Mark Wielaard <mark@klomp.org>
Jeroen Frijters <jeroen@sumatra.nl>
* java/net/URLClassLoader.java (Resource.getCodeSource):
Fix check certs == null.
(getCanonicalFileURL): Removed method.
(JarURLLoader): Don't call removed method.
(FileURLLoader): Likewise.
(FileURLLoader.getResource): Don't canonicalize file name.
With his patch all Mauve URLClassLoader tests pass, there are no
regressions and it makes Eclipse run as before.
OK for mainline and branch?
Cheers,
Mark
Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLClassLoader.java,v
retrieving revision 1.12
diff -u -r1.12 URLClassLoader.java
--- java/net/URLClassLoader.java 11 Dec 2002 02:13:51 -0000 1.12
+++ java/net/URLClassLoader.java 29 Dec 2002 21:52:16 -0000
@@ -238,7 +238,7 @@
CodeSource getCodeSource()
{
Certificate[] certs = getCertificates();
- if (certs != null)
+ if (certs == null)
return loader.noCertCodeSource;
else
return new CodeSource(loader.baseURL, certs);
@@ -271,34 +271,18 @@
abstract InputStream getInputStream() throws IOException;
}
- static URL getCanonicalFileURL(URL url)
- {
- if ("file".equals(url.getProtocol()))
- {
- try
- {
- File f = new File(url.getFile()).getCanonicalFile();
- url = new URL("file", "", f.toString());
- }
- catch (IOException ignore)
- {
- }
- }
- return url;
- }
-
/**
* A <code>JarURLLoader</code> is a type of <code>URLLoader</code>
* only loading from jar url.
*/
final static class JarURLLoader extends URLLoader
{
- final JarFile jarfile; // The canonical jar file for this url
+ final JarFile jarfile; // The jar file for this url
final URL baseJarURL; // Base jar: url for all resources loaded from jar
public JarURLLoader(URLClassLoader classloader, URL baseURL)
{
- super(classloader, getCanonicalFileURL(baseURL));
+ super(classloader, baseURL);
// cache url prefix for all resources in this jar url
String external = baseURL.toExternalForm();
@@ -481,11 +465,11 @@
*/
final static class FileURLLoader extends URLLoader
{
- File dir; //the canonical file for this file url
+ File dir; //the file for this file url
FileURLLoader(URLClassLoader classloader, URL url)
{
- super(classloader, getCanonicalFileURL(url));
+ super(classloader, url);
dir = new File(baseURL.getFile());
}
@@ -493,13 +477,6 @@
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);
return null;