8213429: Windows file handling redux
authoraefimov
Mon, 20 May 2019 15:57:16 +0100
changeset 58617 037ca385e957
parent 58616 be9ef671a1b6
child 58618 a95e1f6757c7
8213429: Windows file handling redux Reviewed-by: alanb, dfuchs, weijun, bpb, rhalade, ahgross
src/java.base/share/classes/java/io/FilePermission.java
--- a/src/java.base/share/classes/java/io/FilePermission.java	Sun May 19 17:20:21 2019 -0700
+++ b/src/java.base/share/classes/java/io/FilePermission.java	Mon May 20 15:57:16 2019 +0100
@@ -367,12 +367,22 @@
             this.mask = mask;
 
             if (cpath.equals("<<ALL FILES>>")) {
+                allFiles = true;
                 directory = true;
                 recursive = true;
                 cpath = "";
                 return;
             }
 
+            // Validate path by platform's default file system
+            try {
+                String name = cpath.endsWith("*") ? cpath.substring(0, cpath.length() - 1) + "-" : cpath;
+                builtInFS.getPath(new File(name).getPath());
+            } catch (InvalidPathException ipe) {
+                invalid = true;
+                return;
+            }
+
             // store only the canonical cpath if possible
             cpath = AccessController.doPrivileged(new PrivilegedAction<>() {
                 public String run() {
@@ -576,19 +586,19 @@
      * @return the effective mask
      */
     boolean impliesIgnoreMask(FilePermission that) {
+        if (this == that) {
+            return true;
+        }
+        if (allFiles) {
+            return true;
+        }
+        if (this.invalid || that.invalid) {
+            return false;
+        }
+        if (that.allFiles) {
+            return false;
+        }
         if (FilePermCompat.nb) {
-            if (this == that) {
-                return true;
-            }
-            if (allFiles) {
-                return true;
-            }
-            if (this.invalid || that.invalid) {
-                return false;
-            }
-            if (that.allFiles) {
-                return false;
-            }
             // Left at least same level of wildness as right
             if ((this.recursive && that.recursive) != that.recursive
                     || (this.directory && that.directory) != that.directory) {
@@ -786,10 +796,10 @@
 
         FilePermission that = (FilePermission) obj;
 
+        if (this.invalid || that.invalid) {
+            return false;
+        }
         if (FilePermCompat.nb) {
-            if (this.invalid || that.invalid) {
-                return false;
-            }
             return (this.mask == that.mask) &&
                     (this.allFiles == that.allFiles) &&
                     this.npath.equals(that.npath) &&
@@ -798,6 +808,7 @@
                     (this.recursive == that.recursive);
         } else {
             return (this.mask == that.mask) &&
+                    (this.allFiles == that.allFiles) &&
                     this.cpath.equals(that.cpath) &&
                     (this.directory == that.directory) &&
                     (this.recursive == that.recursive);