File.getAbsolutePath() bugfix

Mike Linksvayer ml at gondwanaland.com
Thu Jan 13 10:24:32 PST 2000


File.getAbsolutePath() was not stripping out extra "." path
components, which is contrary to the behavior of the JDK, and
breaks user code that relies on the JDK behavior.  getCanonicalPath()
was also broken was a result.

The following code produces a simple case:

	System.err.println(new File(".").getAbsolutePath());

If current directory is /foo, output under the JDK is "/foo", output
under Kaffe is "/foo/.".

I've included a simple patch below, and I'll look into a regression
test soon.


Index: java/io/File.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/io/File.java,v
retrieving revision 1.21
diff -u -r1.21 File.java
--- java/io/File.java   1999/10/12 19:05:45     1.21
+++ java/io/File.java   2000/01/13 18:05:35
@@ -156,7 +156,15 @@
                return getPath();
        }
        else {
-               return System.getProperty("user.dir") + separatorChar + getPath(
);
+               String path = getPath();
+               String userDir = System.getProperty("user.dir");
+               if (path.equals(".")) {
+                       return userDir;
+               }
+               if (path.startsWith("./")) {
+                       path = path.substring(2);
+               }
+               return userDir + separatorChar + path;
        }
 }
 

-- 
                              See From: and Organization: above.


More information about the kaffe mailing list