changeset 56034:a445d4305fad

8229899: Make java.io.File.isInvalid() less racy Reviewed-by: alanb, martin, shade
author aeubanks
date Mon, 19 Aug 2019 16:08:28 -0700
parents 348f7933e2cc
children 1ba30faf88e5
files src/java.base/share/classes/java/io/File.java
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }
 
     /**