This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC Patch: only add absolute file paths to URLClassLoader


On Wed, 2005-07-27 at 11:55 -0600, Tom Tromey wrote:
> I couldn't really think of a way to write a Mauve test for this.
> I suppose with strace at least we could see whether relative or
> absolute file names are being opened.  But ... what difference would
> it make?  It seems to me that patching URLClassLoader will yield
> correct results (as far as can be observed); and I couldn't think of
> a problem with this approach.  Note though that you can't modify the
> URLs as reported by getURLs.

Ok, this patch seems to do all the right things.  What do you think?

AG


2005-09-15  Anthony Green  <green@redhat.com>

	* java/net/URLClassLoader.java (FileURLLoader.getResource): File
	resources should all have canonicalized names.


Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLClassLoader.java,v
retrieving revision 1.31
diff -u -r1.31 URLClassLoader.java
--- java/net/URLClassLoader.java	30 Jun 2005 03:20:02 -0000	1.31
+++ java/net/URLClassLoader.java	16 Sep 2005 03:22:54 -0000
@@ -610,9 +610,16 @@
     /** get resource with the name "name" in the file url */
     Resource getResource(String name)
     {
-      File file = new File(dir, name);
-      if (file.exists())
-        return new FileResource(this, name, file);
+      try 
+	{
+	  File file = new File(dir, name).getCanonicalFile();
+	  if (file.exists() && !file.isDirectory())
+	    return new FileResource(this, file.path(), file);
+	}
+      catch (IOException e)
+	{
+	  // Fall through...
+	}
       return null;
     }
   }



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]