8072495: (fs) Path.relativize() gives incorrect result for empty path on Windows
authorbpb
Fri, 06 Feb 2015 08:05:44 -0800
changeset 28847 5667388e3a79
parent 28846 b96683be2713
child 28848 824124d1cba5
8072495: (fs) Path.relativize() gives incorrect result for empty path on Windows Summary: Correct handling of empty path in Windows version of relativize() Reviewed-by: alanb, dfuchs
jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java
jdk/test/java/nio/file/Path/PathOps.java
--- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java	Fri Feb 06 09:57:28 2015 +0100
+++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java	Fri Feb 06 08:05:44 2015 -0800
@@ -391,6 +391,10 @@
         if (!this.root.equalsIgnoreCase(other.root))
             throw new IllegalArgumentException("'other' has different root");
 
+        // this path is the empty path
+        if (this.isEmpty())
+            return other;
+
         int bn = this.getNameCount();
         int cn = other.getNameCount();
 
--- a/jdk/test/java/nio/file/Path/PathOps.java	Fri Feb 06 09:57:28 2015 +0100
+++ b/jdk/test/java/nio/file/Path/PathOps.java	Fri Feb 06 08:05:44 2015 -0800
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4313887 6838333 6925932 7006126 8037945
+ * @bug 4313887 6838333 6925932 7006126 8037945 8072495
  * @summary Unit test for java.nio.file.Path path operations
  */
 
@@ -516,7 +516,9 @@
             .relativize("\\\\server\\share\\bar", "..\\bar")
             .relativize("\\\\server\\share\\foo", "");
         test("")
-            .relativize("", "");
+            .relativize("", "")
+            .relativize("a", "a")
+            .relativize("a\\b\\c", "a\\b\\c");
 
         // normalize
         test("C:\\")