File.java File (String,String): Fixed handling of empty path.
authorJeroen Frijters <jeroen@frijters.net>
Mon, 30 Aug 2004 14:19:57 +0000 (14:19 +0000)
committerAndreas Tobler <andreast@gcc.gnu.org>
Mon, 30 Aug 2004 14:19:57 +0000 (16:19 +0200)
2004-08-30  Jeroen Frijters  <jeroen@frijters.net>

* java/io/File.java File(String,String): Fixed handling of empty
path.

From-SVN: r86774

libjava/ChangeLog
libjava/java/io/File.java

index 5093b39beb83781fa21679f658f395c055200414..96b505b1641d60821ea2981039ccfe950ab33251 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-30  Jeroen Frijters  <jeroen@frijters.net>
+
+       * java/io/File.java File(String,String): Fixed handling of empty
+       path.
+
 2004-08-30  Casey Marshall  <csm@gnu.org>
 
        Author e-mail updated for all files.
index 1d930d59b84d0f20589eae836feedd8c9b80a10e..2626d47e9e14a61b8af5c36f21bfce4ce75b0256 100644 (file)
@@ -361,14 +361,37 @@ public class File implements Serializable, Comparable
   {
     if (name == null)
       throw new NullPointerException();
-    if (dirPath != null && dirPath.length() > 0)
+    if (dirPath != null)
       {
-       // Try to be smart about the number of separator characters.
-       if (dirPath.charAt(dirPath.length() - 1) == separatorChar
-           || name.length() == 0)
-         path = normalizePath(dirPath + name);
+       if (dirPath.length() > 0)
+         {
+           // Try to be smart about the number of separator characters.
+           if (dirPath.charAt(dirPath.length() - 1) == separatorChar
+               || name.length() == 0)
+             path = normalizePath(dirPath + name);
+           else
+             path = normalizePath(dirPath + separatorChar + name);
+         }
        else
-         path = normalizePath(dirPath + separatorChar + name);
+         {
+           // If dirPath is empty, use a system dependant
+           // default prefix.
+           // Note that the leading separators in name have
+           // to be chopped off, to prevent them forming
+           // a UNC prefix on Windows.
+           if (separatorChar == '\\' /* TODO use ON_WINDOWS */)
+             {
+               int skip = 0;
+               while(name.length() > skip
+                   && (name.charAt(skip) == separatorChar
+                   || name.charAt(skip) == '/'))
+                 {
+                   skip++;
+                 }
+               name = name.substring(skip);
+             }
+           path = normalizePath(separatorChar + name);
+         }
       }
     else
       path = normalizePath(name);