8213406: (fs) More than one instance of built-in FileSystem observed in heap

Reviewed-by: alanb, cushon, weijun
This commit is contained in:
Martin Buchholz 2018-11-28 14:28:28 -08:00
parent 978c78f7fc
commit 7212bf0a77
14 changed files with 106 additions and 53 deletions

View file

@ -25,7 +25,6 @@
package java.io;
import java.net.URI;
import java.nio.file.*;
import java.security.*;
import java.util.Enumeration;
@ -199,12 +198,11 @@ public final class FilePermission extends Permission implements Serializable {
private static final long serialVersionUID = 7930732926638008763L;
/**
* Always use the internal default file system, in case it was modified
* with java.nio.file.spi.DefaultFileSystemProvider.
* Use the platform's default file system to avoid recursive initialization
* issues when the VM is configured to use a custom file system provider.
*/
private static final java.nio.file.FileSystem builtInFS =
DefaultFileSystemProvider.create()
.getFileSystem(URI.create("file:///"));
DefaultFileSystemProvider.theFileSystem();
private static final Path here = builtInFS.getPath(
GetPropertyAction.privilegedGetProperty("user.dir"));
@ -326,7 +324,7 @@ public final class FilePermission extends Permission implements Serializable {
if (name.equals("<<ALL FILES>>")) {
allFiles = true;
npath = builtInFS.getPath("");
npath = EMPTY_PATH;
// other fields remain default
return;
}
@ -351,7 +349,7 @@ public final class FilePermission extends Permission implements Serializable {
npath = npath.getParent();
}
if (npath == null) {
npath = builtInFS.getPath("");
npath = EMPTY_PATH;
}
invalid = false;
} catch (InvalidPathException ipe) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 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
@ -37,6 +37,7 @@ import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import jdk.internal.misc.VM;
import sun.nio.fs.DefaultFileSystemProvider;
/**
* Factory methods for file systems. This class defines the {@link #getDefault
@ -88,16 +89,6 @@ import jdk.internal.misc.VM;
public final class FileSystems {
private FileSystems() { }
// Built-in file system provider
private static final FileSystemProvider builtinFileSystemProvider =
sun.nio.fs.DefaultFileSystemProvider.create();
// built-in file system
private static class BuiltinFileSystemHolder {
static final FileSystem builtinFileSystem =
builtinFileSystemProvider.getFileSystem(URI.create("file:///"));
}
// lazy initialization of default file system
private static class DefaultFileSystemHolder {
static final FileSystem defaultFileSystem = defaultFileSystem();
@ -118,7 +109,8 @@ public final class FileSystems {
// returns default provider
private static FileSystemProvider getDefaultProvider() {
FileSystemProvider provider = builtinFileSystemProvider;
// start with the platform's default file system provider
FileSystemProvider provider = DefaultFileSystemProvider.instance();
// if the property java.nio.file.spi.DefaultFileSystemProvider is
// set then its value is the name of the default provider (or a list)
@ -189,7 +181,8 @@ public final class FileSystems {
if (VM.isModuleSystemInited()) {
return DefaultFileSystemHolder.defaultFileSystem;
} else {
return BuiltinFileSystemHolder.builtinFileSystem;
// always use the platform's default file system during startup
return DefaultFileSystemProvider.theFileSystem();
}
}