< prev index next >

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

Print this page
rev 56147 : 8229899: Make java.io.File.isInvalid() less racy


 165 
 166     /**
 167      * Enum type that indicates the status of a file path.
 168      */
 169     private static enum PathStatus { INVALID, CHECKED };
 170 
 171     /**
 172      * The flag indicating whether the file path is invalid.
 173      */
 174     private transient PathStatus status = null;
 175 
 176     /**
 177      * Check if the file has an invalid path. Currently, the inspection of
 178      * a file path is very limited, and it only covers Nul character check.
 179      * Returning true means the path is definitely invalid/garbage. But
 180      * returning false does not guarantee that the path is valid.
 181      *
 182      * @return true if the file path is invalid.
 183      */
 184     final boolean isInvalid() {
 185         if (status == null) {
 186             status = (this.path.indexOf('\u0000') < 0) ? PathStatus.CHECKED
 187                                                        : PathStatus.INVALID;


 188         }
 189         return status == PathStatus.INVALID;
 190     }
 191 
 192     /**
 193      * The length of this abstract pathname's prefix, or zero if it has no
 194      * prefix.
 195      */
 196     private final transient int prefixLength;
 197 
 198     /**
 199      * Returns the length of this abstract pathname's prefix.
 200      * For use by FileSystem classes.
 201      */
 202     int getPrefixLength() {
 203         return prefixLength;
 204     }
 205 
 206     /**
 207      * The system-dependent default name-separator character.  This field is
 208      * initialized to contain the first character of the value of the system
 209      * property <code>file.separator</code>.  On UNIX systems the value of this




 165 
 166     /**
 167      * Enum type that indicates the status of a file path.
 168      */
 169     private static enum PathStatus { INVALID, CHECKED };
 170 
 171     /**
 172      * The flag indicating whether the file path is invalid.
 173      */
 174     private transient PathStatus status = null;
 175 
 176     /**
 177      * Check if the file has an invalid path. Currently, the inspection of
 178      * a file path is very limited, and it only covers Nul character check.
 179      * Returning true means the path is definitely invalid/garbage. But
 180      * returning false does not guarantee that the path is valid.
 181      *
 182      * @return true if the file path is invalid.
 183      */
 184     final boolean isInvalid() {
 185         PathStatus s = status;
 186         if (s == null) {
 187             s = (this.path.indexOf('\u0000') < 0) ? PathStatus.CHECKED
 188                                                   : PathStatus.INVALID;
 189             status = s;
 190         }
 191         return s == PathStatus.INVALID;
 192     }
 193 
 194     /**
 195      * The length of this abstract pathname's prefix, or zero if it has no
 196      * prefix.
 197      */
 198     private final transient int prefixLength;
 199 
 200     /**
 201      * Returns the length of this abstract pathname's prefix.
 202      * For use by FileSystem classes.
 203      */
 204     int getPrefixLength() {
 205         return prefixLength;
 206     }
 207 
 208     /**
 209      * The system-dependent default name-separator character.  This field is
 210      * initialized to contain the first character of the value of the system
 211      * property <code>file.separator</code>.  On UNIX systems the value of this


< prev index next >