8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
8153248: (zipfs) ZipPath#getFileName( ) returns inconsistent result
8146754: (zipfs) ZipPath.relativize() returns wrong result for path ending with slash /
8139956: (zipfs) ZipPath does not produce correct empty path on relativize()
Reviewed-by: alanb, shurailine
--- a/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java Wed May 25 13:38:35 2016 -0700
+++ b/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java Wed May 25 13:53:03 2016 -0700
@@ -376,12 +376,17 @@
// count names
count = 0;
index = 0;
- while (index < path.length) {
- byte c = path[index++];
- if (c != '/') {
- count++;
- while (index < path.length && path[index] != '/')
- index++;
+ if (path.length == 0) {
+ // empty path has one name
+ count = 1;
+ } else {
+ while (index < path.length) {
+ byte c = path[index++];
+ if (c != '/') {
+ count++;
+ while (index < path.length && path[index] != '/')
+ index++;
+ }
}
}
// populate offsets
@@ -423,10 +428,11 @@
// removes redundant slashs, replace "\" to zip separator "/"
// and check for invalid characters
private byte[] normalize(byte[] path) {
- if (path.length == 0)
+ int len = path.length;
+ if (len == 0)
return path;
byte prevC = 0;
- for (int i = 0; i < path.length; i++) {
+ for (int i = 0; i < len; i++) {
byte c = path[i];
if (c == '\\' || c == '\u0000')
return normalize(path, i);
@@ -434,6 +440,8 @@
return normalize(path, i - 1);
prevC = c;
}
+ if (len > 1 && prevC == '/')
+ return Arrays.copyOf(path, len - 1);
return path;
}
@@ -567,7 +575,8 @@
if (watcher == null || events == null || modifiers == null) {
throw new NullPointerException();
}
- throw new UnsupportedOperationException();
+ // watcher must be associated with a different provider
+ throw new ProviderMismatchException();
}
@Override
--- a/jdk/test/jdk/nio/zipfs/Basic.java Wed May 25 13:38:35 2016 -0700
+++ b/jdk/test/jdk/nio/zipfs/Basic.java Wed May 25 13:53:03 2016 -0700
@@ -31,6 +31,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.file.ProviderMismatchException;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
@@ -39,14 +40,15 @@
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
-
+import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
/**
* @test
- * @bug 8038500 8040059 8150366 8150496
+ * @bug 8038500 8040059 8150366 8150496 8147539
* @summary Basic test for zip provider
*
* @run main Basic
* @run main/othervm/java.security.policy=test.policy Basic
+ * @modules jdk.zipfs
*/
public class Basic {
@@ -89,7 +91,7 @@
found = false;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(fs.getPath("/"))) {
for (Path entry: stream) {
- found = entry.toString().equals("/META-INF/");
+ found = entry.toString().equals("/META-INF");
if (found) break;
}
}
@@ -117,6 +119,13 @@
if (!store.supportsFileAttributeView("basic"))
throw new RuntimeException("BasicFileAttributeView should be supported");
+ // Test: watch register should throw PME
+ try {
+ fs.getPath("/")
+ .register(FileSystems.getDefault().newWatchService(), ENTRY_CREATE);
+ throw new RuntimeException("watch service is not supported");
+ } catch (ProviderMismatchException x) { }
+
// Test: ClosedFileSystemException
fs.close();
if (fs.isOpen())
--- a/jdk/test/jdk/nio/zipfs/MultiReleaseJarTest.java Wed May 25 13:38:35 2016 -0700
+++ b/jdk/test/jdk/nio/zipfs/MultiReleaseJarTest.java Wed May 25 13:53:03 2016 -0700
@@ -28,6 +28,7 @@
* @library /lib/testlibrary/java/util/jar
* @build Compiler JarBuilder CreateMultiReleaseTestJars
* @run testng MultiReleaseJarTest
+ * @modules jdk.zipfs
*/
import java.io.IOException;
--- a/jdk/test/jdk/nio/zipfs/PathOps.java Wed May 25 13:38:35 2016 -0700
+++ b/jdk/test/jdk/nio/zipfs/PathOps.java Wed May 25 13:53:03 2016 -0700
@@ -31,11 +31,12 @@
/**
*
* @test
- * @bug 8038500 8040059
+ * @bug 8038500 8040059 8139956 8146754
* @summary Tests path operations for zip provider.
*
* @run main PathOps
* @run main/othervm/java.security.policy=test.policy PathOps
+ * @modules jdk.zipfs
*/
public class PathOps {
@@ -424,6 +425,11 @@
test("/")
.relativize("/a", "a")
.relativize("/a/c", "a/c");
+ // 8146754
+ test("/tmp/path")
+ .relativize("/tmp/path/a.txt", "a.txt");
+ test("/tmp/path/")
+ .relativize("/tmp/path/a.txt", "a.txt");
// normalize
test("/")
@@ -486,7 +492,16 @@
// isSameFile
test("/fileDoesNotExist")
.isSameFile("/fileDoesNotExist");
- }
+
+ // 8139956
+ out.println("check getNameCount");
+ int nc = fs.getPath("/").relativize(fs.getPath("/")).getNameCount();
+ if (nc != 1) {
+ out.format("\tExpected: 1\n");
+ out.format("\tActual: %d\n", nc);
+ throw new RuntimeException("getNameCount of empty path failed");
+ }
+ }
static void npes() {
header("NullPointerException");
--- a/jdk/test/jdk/nio/zipfs/ZFSTests.java Wed May 25 13:38:35 2016 -0700
+++ b/jdk/test/jdk/nio/zipfs/ZFSTests.java Wed May 25 13:53:03 2016 -0700
@@ -22,11 +22,12 @@
*/
/* @test
- * @bug 7156873 8040059 8028480 8034773
+ * @bug 7156873 8040059 8028480 8034773 8153248
* @summary ZipFileSystem regression tests
*
* @run main ZFSTests
* @run main/othervm/java.security.policy=test.policy ZFSTests
+ * @modules jdk.zipfs
*/
@@ -42,7 +43,7 @@
public static void main(String[] args) throws Throwable {
test7156873();
- testOpenOptions();
+ tests();
}
static void test7156873() throws Throwable {
@@ -61,7 +62,7 @@
}
}
- static void testOpenOptions() throws Throwable {
+ static void tests() throws Throwable {
Path path = Paths.get("file.zip");
try {
URI uri = URI.create("jar:" + path.toUri());
@@ -95,6 +96,18 @@
} catch (IllegalArgumentException x) {
// expected x.printStackTrace();
}
+
+ //8153248
+ Path dir = fs.getPath("/dir");
+ Path subdir = fs.getPath("/dir/subdir");
+ Files.createDirectory(dir);
+ Files.createDirectory(subdir);
+ Files.list(dir)
+ .forEach( child -> {
+ System.out.println("child:" + child);
+ if (child.toString().endsWith("/"))
+ throw new RuntimeException("subdir names ends with /");
+ });
}
} finally {
Files.deleteIfExists(path);
--- a/jdk/test/jdk/nio/zipfs/ZipFSTester.java Wed May 25 13:38:35 2016 -0700
+++ b/jdk/test/jdk/nio/zipfs/ZipFSTester.java Wed May 25 13:53:03 2016 -0700
@@ -74,6 +74,7 @@
* @summary Test Zip filesystem provider
* @run main ZipFSTester
* @run main/othervm/java.security.policy=test.policy ZipFSTester
+ * @modules jdk.zipfs
*/
public class ZipFSTester {