diff --git a/jdk/src/solaris/classes/sun/nio/fs/UnixPath.java b/jdk/src/solaris/classes/sun/nio/fs/UnixPath.java index 2741915e55de28253e03fabd54154346261f838b..389034da19745300c392aa202b9b2e4c0e7bbd41 100644 --- a/jdk/src/solaris/classes/sun/nio/fs/UnixPath.java +++ b/jdk/src/solaris/classes/sun/nio/fs/UnixPath.java @@ -624,8 +624,11 @@ class UnixPath public boolean endsWith(Path other) { UnixPath that = checkPath(other); + int thisLen = path.length; + int thatLen = that.path.length; + // other path is longer - if (that.path.length > path.length) + if (thatLen > thisLen) return false; // other path is absolute so this path must be absolute @@ -643,10 +646,10 @@ class UnixPath if (thatOffsetCount == thisOffsetCount) { if (thisOffsetCount == 0) return true; - int expectedLen = path.length; + int expectedLen = thisLen; if (this.isAbsolute() && !that.isAbsolute()) expectedLen--; - if (that.path.length != expectedLen) + if (thatLen != expectedLen) return false; } else { // this path has more elements so given path must be relative @@ -658,7 +661,9 @@ class UnixPath // compare bytes int thisPos = offsets[thisOffsetCount - thatOffsetCount]; int thatPos = that.offsets[0]; - while (thatPos < that.path.length) { + if ((thatLen - thatPos) != (thisLen - thisPos)) + return false; + while (thatPos < thatLen) { if (this.path[thisPos++] != that.path[thatPos++]) return false; } diff --git a/jdk/test/java/nio/file/Path/PathOps.java b/jdk/test/java/nio/file/Path/PathOps.java index 6482d5e88b239f3b3d9918c95d654c3db404217e..3517baacc16455328ea35cef3f5fa7bcad6e7380 100644 --- a/jdk/test/java/nio/file/Path/PathOps.java +++ b/jdk/test/java/nio/file/Path/PathOps.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 4313887 6838333 + * @bug 4313887 6838333 6925932 * @summary Unit test for java.nio.file.Path path operations */ @@ -614,17 +614,34 @@ public class PathOps { test("/foo") .ends("foo") .ends("/foo") - .notEnds("/"); + .notEnds("fool"); test("/foo/bar") .ends("bar") .ends("foo/bar") .ends("/foo/bar") - .notEnds("/bar"); + .notEnds("ar") + .notEnds("barack") + .notEnds("/bar") + .notEnds("o/bar"); test("foo") - .ends("foo"); + .ends("foo") + .notEnds("oo") + .notEnds("oola"); test("foo/bar") .ends("bar") - .ends("foo/bar"); + .ends("foo/bar") + .notEnds("r") + .notEnds("barmaid") + .notEnds("/bar"); + test("foo/bar/gus") + .ends("gus") + .ends("bar/gus") + .ends("foo/bar/gus") + .notEnds("g") + .notEnds("/gus") + .notEnds("r/gus") + .notEnds("barack/gus") + .notEnds("bar/gust"); // elements test("a/b/c")