classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] small bug in new file code


From: Dalibor Topic
Subject: [cp-patches] small bug in new file code
Date: Thu, 12 Aug 2004 04:48:12 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5

Hi Jeroen,

The problem is illustrated by this example from kaffe's regression test suite:

import java.io.File;

public class FileTest {

public static void exists(File f) {
String type = "File";
if (f.isDirectory()) { type = "Directory"; }
System.out.print(type + " \"" + f.getPath() );
if (f.exists()) {
System.out.println("\" does exist");
} else {
System.out.println("\" does not exist");
}
}

public static void main(String[] argv) throws Exception {
File g5 = new File("","NotExist2"); exists(g5);
}
}

it should print File "/NotExist2" does not exist on Unix and
File "\NotExist2" does not exist on Windows.

The relevant API spec bit from 1.4.2 is:

"If parent is the empty string then the new File instance is created by converting child into an abstract pathname and resolving the result against a system-dependent default directory."

the system dependant default dir seems to be / on Linux, and \ on Windows. So I decided to simply use File.separator for it in my attached patch.

cheers,
dalibor topic

ChangeLog:

2004-08-12  Dalibor Topic  <address@hidden>

        * java/io/File.java (File(String, String)): Prepend
        system-dependant default dir if parent is empty.
--- /tmp/topic/classpath/java/io/File.java      2004-07-27 10:44:08.000000000 
+0200
+++ /tmp/topic/kaffe/libraries/javalib/java/io/File.java        2004-08-12 
03:32:32.000000000 +0200
@@ -343,8 +343,8 @@
   {
     if (name == null)
       throw new NullPointerException();
-    if (dirPath != null && dirPath.length() > 0)
-      {
+    if (dirPath != null) {
+      if (dirPath.length() > 0) {
        // Try to be smart about the number of separator characters.
        if (dirPath.charAt(dirPath.length() - 1) == separatorChar
            || name.length() == 0)
@@ -352,6 +352,13 @@
        else
          path = normalizePath(dirPath + separatorChar + name);
       }
+      else {
+       /* if the dirPath is empty, use a system dependant
+        * default prefix.
+        */
+       path = normalizePath(separatorChar + name);
+      }
+    }
     else
       path = normalizePath(name);
   }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]