# HG changeset patch # User sherman # Date 1503548822 25200 # Node ID f63587417ae64d1daa92adcea3f11f43c4d05041 # Parent e92e67ed12b4b9db04811f5ea617fc41363c5a34 8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false Reviewed-by: martin diff -r e92e67ed12b4 -r f63587417ae6 jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java --- a/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java Wed Aug 23 10:58:11 2017 -0700 +++ b/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java Wed Aug 23 21:27:02 2017 -0700 @@ -310,7 +310,10 @@ @Override public boolean startsWith(Path other) { - final ZipPath o = checkPath(other); + Objects.requireNonNull(other, "other"); + if (!(other instanceof ZipPath)) + return false; + final ZipPath o = (ZipPath)other; if (o.isAbsolute() != this.isAbsolute() || o.path.length > this.path.length) return false; @@ -327,7 +330,10 @@ @Override public boolean endsWith(Path other) { - final ZipPath o = checkPath(other); + Objects.requireNonNull(other, "other"); + if (!(other instanceof ZipPath)) + return false; + final ZipPath o = (ZipPath)other; int olast = o.path.length - 1; if (olast > 0 && o.path[olast] == '/') olast--; diff -r e92e67ed12b4 -r f63587417ae6 jdk/test/jdk/nio/zipfs/PathOps.java --- a/jdk/test/jdk/nio/zipfs/PathOps.java Wed Aug 23 10:58:11 2017 -0700 +++ b/jdk/test/jdk/nio/zipfs/PathOps.java Wed Aug 23 21:27:02 2017 -0700 @@ -27,11 +27,13 @@ import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.ProviderMismatchException; /** * * @test - * @bug 8038500 8040059 8139956 8146754 8172921 + * @bug 8038500 8040059 8139956 8146754 8172921 8186142 * @summary Tests path operations for zip provider. * * @run main PathOps @@ -571,16 +573,46 @@ } + static void mismatchedProviders() { + header("ProviderMismatchException"); + Path path = fs.getPath("foo"); + Path other = Paths.get("foo"); + try { + path.compareTo(other); + throw new RuntimeException("ProviderMismatchException not thrown"); + } catch (ProviderMismatchException pme) {} + + try { + path.resolve(other); + throw new RuntimeException("ProviderMismatchException not thrown"); + } catch (ProviderMismatchException pme) {} + + try { + path.relativize(other); + throw new RuntimeException("ProviderMismatchException not thrown"); + } catch (ProviderMismatchException pme) {} + + try { + if (path.startsWith(other)) + throw new RuntimeException("providerMismatched startsWith() returns true "); + if (path.endsWith(other)) + throw new RuntimeException("providerMismatched endsWith() returns true "); + } catch (ProviderMismatchException pme) { + throw new RuntimeException("ProviderMismatchException is thrown for starts/endsWith()"); + } + } + public static void main(String[] args) throws IOException { // create empty JAR file, test doesn't require any contents Path emptyJar = Utils.createJarFile("empty.jar"); fs = FileSystems.newFileSystem(emptyJar, null); try { - npes(); - doPathOpTests(); + npes(); + mismatchedProviders(); + doPathOpTests(); } finally { - fs.close(); + fs.close(); + } } } -}