8229899: Make java.io.File.isInvalid() less racy
authoraeubanks
Mon, 19 Aug 2019 16:08:28 -0700
changeset 57816 a445d4305fad
parent 57815 348f7933e2cc
child 57817 1ba30faf88e5
8229899: Make java.io.File.isInvalid() less racy Reviewed-by: alanb, martin, shade
src/java.base/share/classes/java/io/File.java
--- a/src/java.base/share/classes/java/io/File.java	Tue Aug 20 15:40:49 2019 +0100
+++ b/src/java.base/share/classes/java/io/File.java	Mon Aug 19 16:08:28 2019 -0700
@@ -182,11 +182,13 @@
      * @return true if the file path is invalid.
      */
     final boolean isInvalid() {
-        if (status == null) {
-            status = (this.path.indexOf('\u0000') < 0) ? PathStatus.CHECKED
-                                                       : PathStatus.INVALID;
+        PathStatus s = status;
+        if (s == null) {
+            s = (this.path.indexOf('\u0000') < 0) ? PathStatus.CHECKED
+                                                  : PathStatus.INVALID;
+            status = s;
         }
-        return status == PathStatus.INVALID;
+        return s == PathStatus.INVALID;
     }
 
     /**