8154403: JRT filesystem loaded by JDK8 with URLClassLoader is not closable since JDK-8147460

Reviewed-by: alanb
This commit is contained in:
Xueming Shen 2016-04-18 10:57:11 -07:00
parent 4935f9d64d
commit c536913c21
4 changed files with 9 additions and 8 deletions

View File

@ -101,10 +101,10 @@ public final class JrtFileSystemProvider extends FileSystemProvider {
@Override @Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env) public FileSystem newFileSystem(URI uri, Map<String, ?> env)
throws IOException { throws IOException {
Objects.requireNonNull(env);
checkPermission(); checkPermission();
checkUri(uri); checkUri(uri);
if (env.containsKey("java.home")) {
if (env != null && env.containsKey("java.home")) {
return newFileSystem((String)env.get("java.home"), uri, env); return newFileSystem((String)env.get("java.home"), uri, env);
} else { } else {
return new JrtFileSystem(this, env); return new JrtFileSystem(this, env);

View File

@ -31,6 +31,7 @@ import java.net.URI;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collections;
public class WithSecurityManager { public class WithSecurityManager {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
@ -61,7 +62,7 @@ public class WithSecurityManager {
// check FileSystems.newFileSystem // check FileSystems.newFileSystem
try { try {
FileSystems.newFileSystem(URI.create("jrt:/"), null); FileSystems.newFileSystem(URI.create("jrt:/"), Collections.emptyMap());
if (!allow) throw new RuntimeException("access not expected"); if (!allow) throw new RuntimeException("access not expected");
} catch (SecurityException se) { } catch (SecurityException se) {
if (allow) if (allow)

View File

@ -30,6 +30,7 @@ import java.nio.file.FileSystems;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collections;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@ -69,11 +70,12 @@ public class Main {
private static FileSystem createFsWithURLClassloader(String javaHome) throws IOException{ private static FileSystem createFsWithURLClassloader(String javaHome) throws IOException{
URL url = Paths.get(javaHome, "jrt-fs.jar").toUri().toURL(); URL url = Paths.get(javaHome, "jrt-fs.jar").toUri().toURL();
URLClassLoader loader = new URLClassLoader(new URL[] { url }); URLClassLoader loader = new URLClassLoader(new URL[] { url });
return FileSystems.newFileSystem(URI.create("jrt:/"), null, loader); return FileSystems.newFileSystem(URI.create("jrt:/"),
Collections.emptyMap(),
loader);
} }
private static FileSystem createFsByInstalledProvider() throws IOException { private static FileSystem createFsByInstalledProvider() throws IOException {
return FileSystems.getFileSystem(URI.create("jrt:/")); return FileSystems.getFileSystem(URI.create("jrt:/"));
} }
} }

View File

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8141609 * @bug 8141609 8154403
* @summary Verify JDK 8 can use jrt-fs.jar to work with jrt file system. * @summary Verify JDK 8 can use jrt-fs.jar to work with jrt file system.
* @run main RemoteRuntimeImageTest * @run main RemoteRuntimeImageTest
*/ */
@ -63,7 +63,6 @@ public class RemoteRuntimeImageTest {
String java = jdk8Path.resolve("bin/java").toAbsolutePath().toString(); String java = jdk8Path.resolve("bin/java").toAbsolutePath().toString();
String javac = jdk8Path.resolve("bin/javac").toAbsolutePath().toString(); String javac = jdk8Path.resolve("bin/javac").toAbsolutePath().toString();
Files.createDirectories(Paths.get(".", CLASSES_DIR)); Files.createDirectories(Paths.get(".", CLASSES_DIR));
String jrtJar = Paths.get(TEST_JAVAHOME, JRTFS_JAR).toAbsolutePath().toString(); String jrtJar = Paths.get(TEST_JAVAHOME, JRTFS_JAR).toAbsolutePath().toString();
@ -121,4 +120,3 @@ public class RemoteRuntimeImageTest {
return version.startsWith("\"1.8"); return version.startsWith("\"1.8");
} }
} }