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
--- 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:\\")