--- old/src/java.base/share/classes/java/io/FilePermission.java 2014-12-01 15:04:29.743933272 +0800 +++ new/src/java.base/share/classes/java/io/FilePermission.java 2014-12-01 15:04:29.567933268 +0800 @@ -147,6 +147,10 @@ private String actions; // Left null as long as possible, then // created and re-used in the getAction function. + // Flags to assist in lazy setting. + // Are directory and recursive set? + private transient boolean dir_rec_set = false; + // canonicalized dir path. In the case of // directories, it is the name "/blah/*" or "/blah/-" without // the last character (the "*" or "-"). @@ -188,15 +192,25 @@ if (mask == NONE) throw new IllegalArgumentException("invalid actions mask"); - if ((cpath = getName()) == null) + if (getName() == null) throw new NullPointerException("name can't be null"); this.mask = mask; + } + + /* + * Sets the directory and recursive flag, and does partial processing of the + * path name. + */ + private void get_dir_rec() { + + cpath = getName(); if (cpath.equals("<>")) { directory = true; recursive = true; cpath = ""; + dir_rec_set = true; return; } @@ -225,12 +239,12 @@ char last = ((len > 0) ? cpath.charAt(len - 1) : 0); if (last == RECURSIVE_CHAR && - cpath.charAt(len - 2) == File.separatorChar) { + (len == 1 || cpath.charAt(len - 2) == File.separatorChar)) { directory = true; recursive = true; cpath = cpath.substring(0, --len); } else if (last == WILD_CHAR && - cpath.charAt(len - 2) == File.separatorChar) { + (len == 1 || cpath.charAt(len - 2) == File.separatorChar)) { directory = true; //recursive = false; cpath = cpath.substring(0, --len); @@ -242,6 +256,7 @@ } // XXX: at this point the path should be absolute. die if it isn't? + dir_rec_set = true; } /** @@ -336,6 +351,10 @@ * @return the effective mask */ boolean impliesIgnoreMask(FilePermission that) { + if (this.getName().equals("<>")) + return true; + if (!this.dir_rec_set) this.get_dir_rec(); + if (!that.dir_rec_set) that.get_dir_rec(); if (this.directory) { if (this.recursive) { // make sure that.path is longer then path so @@ -396,6 +415,8 @@ FilePermission that = (FilePermission) obj; + if (!this.dir_rec_set) this.get_dir_rec(); + if (!that.dir_rec_set) that.get_dir_rec(); return (this.mask == that.mask) && this.cpath.equals(that.cpath) && (this.directory == that.directory) &&