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]

RFC Patch: only add absolute file paths to URLClassLoader


Found while attempting to run Azureus on HEAD.

        String urlString = bug.class.getClassLoader().getResource("bug.class").toExternalForm ();
        System.out.println (urlString);

If bug.class is in your cwd, this currently prints file:./bug.class.
But I believe this should really be an absolute path, like
file:///tmp/bug.class, or something like that.

Azurues stumbles on this because it creates URIs from these URLs, and
then URI.getPath() throws an NPE.  Turning this into an absolute path
fixes the problem.

This patch simply makes sure we only add absolute paths to
URLClassLoader.  But now that I think about it, maybe we should turn
these into absolute paths within URLClassLoader itself.  Comments?


2005-07-24  Anthony Green  <green@redhat.com>

	* gnu/gcj/runtime/SystemClassLoader.java: Only add file: URLs with
	absolute pathes to URLClassLoader.


Index: gnu/gcj/runtime/SystemClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/SystemClassLoader.java,v
retrieving revision 1.3
diff -u -p -r1.3 SystemClassLoader.java
--- gnu/gcj/runtime/SystemClassLoader.java	15 Jun 2005 19:05:43 -0000	1.3
+++ gnu/gcj/runtime/SystemClassLoader.java	24 Jul 2005 19:15:32 -0000
@@ -43,8 +43,14 @@ public final class SystemClassLoader ext
 	      {
 		if (last_was_sep)
 		  {
-		    // We saw two separators in a row, so add ".".
-		    addURL(new URL("file", "", -1, "./"));
+		    // We saw two separators in a row, so add the
+		    // current working directory.
+		    File cwd = new File (".");
+		    e = cwd.getAbsolutePath ();
+		    if (!e.endsWith (File.separator))
+		      addURL(new URL("file", "", -1, e + File.separator));
+		    else
+		      addURL(new URL("file", "", -1, e));
 		    last_was_sep = false;
 		  }
 		else
@@ -57,6 +63,8 @@ public final class SystemClassLoader ext
 	    // Ignore invalid paths.
 	    if (!path.exists())
 	      continue;
+	    // Only deal in absolute paths.
+	    e = path.getAbsolutePath ();
 	    if (!e.endsWith (File.separator) && path.isDirectory ())
 	      addURL(new URL("file", "", -1, e + File.separator));
 	    else

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