Patch: FYI: empty entries in class path

Tom Tromey tromey@redhat.com
Fri May 13 20:03:00 GMT 2005


I'm checking this in on the trunk and the 4.0 branch.

Andrew Pinski pointed out that an entry element in CLASSPATH ought to
be treated as '.'.  Fixed as appended.

Note that we don't share this code with Classpath.  There is similar
code there, but it is in ClassLoader, and looked slightly buggy to me.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* gnu/gcj/runtime/SystemClassLoader.java (init): Handle empty
	element in path.

Index: gnu/gcj/runtime/SystemClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/SystemClassLoader.java,v
retrieving revision 1.1
diff -u -r1.1 SystemClassLoader.java
--- gnu/gcj/runtime/SystemClassLoader.java 2 Feb 2005 20:59:39 -0000 1.1
+++ gnu/gcj/runtime/SystemClassLoader.java 13 May 2005 19:54:01 -0000
@@ -27,16 +27,30 @@
   // causing a crash.
   void init()
   {
+    String sep = File.pathSeparator;
     StringTokenizer st
       = new StringTokenizer (System.getProperty ("java.class.path", "."),
-			     File.pathSeparator);
+			     sep, true);
+    // Pretend we start with a ':', so if we see a ':' first we add
+    // '.'.
+    boolean last_was_sep = true;
     while (st.hasMoreElements ()) 
       {  
 	String e = st.nextToken ();
 	try
 	  {
-	    if ("".equals(e))
-	      e = ".";
+	    if (sep.equals(e))
+	      {
+		if (last_was_sep)
+		  {
+		    // We saw two separators in a row, so add ".".
+		    addURL(new URL("file", "", -1, "./"));
+		    last_was_sep = false;
+		  }
+		else
+		  last_was_sep = true;
+		continue;
+	      }
 
 	    File path = new File(e);
 	    // Ignore invalid paths.
@@ -53,5 +67,18 @@
 	    throw new RuntimeException(x);
 	  }
       }
+    // If we saw a trailing ":", add "." to the path.
+    if (last_was_sep)
+      {
+	try
+	  {
+	    addURL(new URL("file", "", -1, "./"));
+	  }
+	catch (java.net.MalformedURLException x)
+	  {
+	    // This should never happen.
+	    throw new RuntimeException(x);
+	  }
+      }
   }
 }



More information about the Java-patches mailing list