8193802: NullPointerException from JarFileSystem.getVersionMap()
Reviewed-by: mchung
--- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java Wed Jan 31 11:25:34 2018 -0800
+++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java Wed Jan 31 14:21:52 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -109,7 +109,9 @@
*/
private Function<byte[],byte[]> createVersionedLinks(int version) {
HashMap<IndexNode,byte[]> aliasMap = new HashMap<>();
- getVersionMap(version, getInode(getBytes("/META-INF/versions"))).values()
+ IndexNode verdir = getInode(getBytes("/META-INF/versions"));
+ if (verdir != null) {
+ getVersionMap(version, verdir).values()
.forEach(versionNode -> { // for each META-INF/versions/{n} directory
// put all the leaf inodes, i.e. entries, into the alias map
// possibly shadowing lower versioned entries
@@ -124,6 +126,7 @@
}
});
});
+ }
return path -> aliasMap.get(IndexNode.keyOf(path));
}
--- a/test/jdk/jdk/nio/zipfs/MultiReleaseJarTest.java Wed Jan 31 11:25:34 2018 -0800
+++ b/test/jdk/jdk/nio/zipfs/MultiReleaseJarTest.java Wed Jan 31 14:21:52 2018 -0800
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8144355 8144062 8176709 8194070
+ * @bug 8144355 8144062 8176709 8194070 8193802
* @summary Test aliasing additions to ZipFileSystem for multi-release jar files
* @library /lib/testlibrary/java/util/jar
* @build Compiler JarBuilder CreateMultiReleaseTestJars
@@ -204,6 +204,21 @@
//testCustomMultiReleaseValue("true\r\n true", false);
}
+ @Test
+ public void testMultiReleaseJarWithNonVersionDir() throws Exception {
+ String jfname = "multi-release-non-ver.jar";
+ Path jfpath = Paths.get(jfname);
+ URI uri = new URI("jar", jfpath.toUri().toString() , null);
+ JarBuilder jb = new JarBuilder(jfname);
+ jb.addAttribute("Multi-Release", "true");
+ jb.build();
+ Map<String,String> env = Map.of("multi-release", "runtime");
+ try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {
+ Assert.assertTrue(true);
+ }
+ Files.delete(jfpath);
+ }
+
private static final AtomicInteger JAR_COUNT = new AtomicInteger(0);
private void testCustomMultiReleaseValue(String value, boolean expected)