8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
Reviewed-by: martin
This commit is contained in:
parent
0ad228775f
commit
1152b56c5b
@ -310,7 +310,10 @@ final class ZipPath implements Path {
|
||||
|
||||
@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 @@ final class ZipPath implements Path {
|
||||
|
||||
@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--;
|
||||
|
@ -27,11 +27,13 @@ import java.nio.file.FileSystems;
|
||||
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 @@ public class PathOps {
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user