harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r470497 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/File.java test/java/org/apache/harmony/luni/tests/java/io/FileTest.java
Date Thu, 02 Nov 2006 20:07:03 GMT
Author: apetrenko
Date: Thu Nov  2 12:07:02 2006
New Revision: 470497

URL: http://svn.apache.org/viewvc?view=rev&rev=470497
Log:
HARMONY-829 [classlib][io] unexpected result for java.io.File.compareTo(File) method

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java?view=diff&rev=470497&r1=470496&r2=470497
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
Thu Nov  2 12:07:02 2006
@@ -169,19 +169,27 @@
 	}
 
 	private String calculatePath(String dirPath, String name) {
-		// Remove all the proceeding separator chars from name
-		name = fixSlashes(name);
-		while (name.length() > 0 && (name.charAt(0) == separatorChar)) {
-            name = name.substring(1, name.length());
-        }
 
-		// Ensure there is a separator char between dirPath and name
-		dirPath = fixSlashes(dirPath);
-		if (dirPath.length() > 0 && (dirPath.charAt(dirPath.length() - 1) == separatorChar))
{
-			return dirPath + name;
-		}
+        dirPath = fixSlashes(dirPath);
+
+        if (name != ""){
+
+            // Remove all the proceeding separator chars from name
+            name = fixSlashes(name);
+            while (name.length() > 0 && (name.charAt(0) == separatorChar)) {
+                name = name.substring(1, name.length());
+            }
 
-		return dirPath + separatorChar + name;
+            // Ensure there is a separator char between dirPath and name
+            if (dirPath.length() > 0 && (dirPath.charAt(dirPath.length() - 1)
== separatorChar)) {
+                return dirPath + name;
+            } else {
+                return dirPath + separatorChar + name;
+            }
+
+        }
+        
+        return dirPath;
 	}
 
 	private void checkURI(URI uri) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java?view=diff&rev=470497&r1=470496&r2=470497
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java
Thu Nov  2 12:07:02 2006
@@ -97,4 +97,28 @@
         file = new File((String) null, "x/y/z");
         assertEquals("x" + separator + "y" + separator + "z", file.getPath());
     }
+    
+    /**
+     * @tests java.io.File#getPath()
+     */
+    public void test_getPath_With_Empty_FileName() {
+        // Regression for HARMONY-829
+        String f1ParentName = "01";
+        File f1 = new File(f1ParentName, "");
+        assertEquals(f1ParentName, f1.getPath());
+        
+        String f2ParentName = "0";
+        File f2 = new File(f2ParentName, "");
+
+        assertEquals(-1, f2.compareTo(f1));
+        assertEquals(1, f1.compareTo(f2));
+
+        File parent = new File(System.getProperty("user.dir"));
+        File f3 = new File(parent, "");
+
+        assertEquals(parent.getPath(), f3.getPath());
+        
+        
+    }
+
 }



Mime
View raw message