< prev index next >

src/java.base/share/classes/java/io/FilePermission.java

Print this page
8213406: (fs) More than one instance of built-in FileSystem observed in heap
Reviewed-by: alanb, cushon, weijun

@@ -34,14 +34,14 @@
 import java.util.Vector;
 import java.util.concurrent.ConcurrentHashMap;
 
 import jdk.internal.access.JavaIOFilePermissionAccess;
 import jdk.internal.access.SharedSecrets;
-import sun.nio.fs.DefaultFileSystemProvider;
 import sun.security.action.GetPropertyAction;
 import sun.security.util.FilePermCompat;
 import sun.security.util.SecurityConstants;
+import static sun.nio.fs.BuiltinFileSystemProvider.BUILTIN_FILE_SYSTEM;
 
 /**
  * This class represents access to a file or directory.  A FilePermission consists
  * of a pathname and a set of actions valid for that pathname.
  * <P>

@@ -196,24 +196,19 @@
 //        return sb.toString();
 //    }
 
     private static final long serialVersionUID = 7930732926638008763L;
 
-    /**
-     * Always use the internal default file system, in case it was modified
-     * with java.nio.file.spi.DefaultFileSystemProvider.
-     */
-    private static final java.nio.file.FileSystem builtInFS =
-            DefaultFileSystemProvider.create()
-                    .getFileSystem(URI.create("file:///"));
+    // Always use the internal default file system, in case it was modified
+    // with the java.nio.file.spi.DefaultFileSystemProvider system property.
 
-    private static final Path here = builtInFS.getPath(
+    private static final Path here = BUILTIN_FILE_SYSTEM.getPath(
             GetPropertyAction.privilegedGetProperty("user.dir"));
 
-    private static final Path EMPTY_PATH = builtInFS.getPath("");
-    private static final Path DASH_PATH = builtInFS.getPath("-");
-    private static final Path DOTDOT_PATH = builtInFS.getPath("..");
+    private static final Path EMPTY_PATH  = BUILTIN_FILE_SYSTEM.getPath("");
+    private static final Path DASH_PATH   = BUILTIN_FILE_SYSTEM.getPath("-");
+    private static final Path DOTDOT_PATH = BUILTIN_FILE_SYSTEM.getPath("..");
 
     /**
      * A private constructor that clones some and updates some,
      * always with a different name.
      * @param input

@@ -324,11 +319,11 @@
 
             this.mask = mask;
 
             if (name.equals("<<ALL FILES>>")) {
                 allFiles = true;
-                npath = builtInFS.getPath("");
+                npath = EMPTY_PATH;
                 // other fields remain default
                 return;
             }
 
             boolean rememberStar = false;

@@ -339,27 +334,27 @@
             }
 
             try {
                 // new File() can "normalize" some name, for example, "/C:/X" on
                 // Windows. Some JDK codes generate such illegal names.
-                npath = builtInFS.getPath(new File(name).getPath())
+                npath = BUILTIN_FILE_SYSTEM.getPath(new File(name).getPath())
                         .normalize();
                 // lastName should always be non-null now
                 Path lastName = npath.getFileName();
                 if (lastName != null && lastName.equals(DASH_PATH)) {
                     directory = true;
                     recursive = !rememberStar;
                     npath = npath.getParent();
                 }
                 if (npath == null) {
-                    npath = builtInFS.getPath("");
+                    npath = EMPTY_PATH;
                 }
                 invalid = false;
             } catch (InvalidPathException ipe) {
                 // Still invalid. For compatibility reason, accept it
                 // but make this permission useless.
-                npath = builtInFS.getPath("-u-s-e-l-e-s-s-");
+                npath = BUILTIN_FILE_SYSTEM.getPath("-u-s-e-l-e-s-s-");
                 invalid = true;
             }
 
         } else {
             if ((cpath = getName()) == null)
< prev index next >