changeset 9981:15a134ed08c4

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 aadfefa63ebc
children 5ae1c2c8952c
files src/share/classes/java/io/File.java
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/io/File.java	Wed May 06 21:01:10 2020 +0200
+++ b/src/share/classes/java/io/File.java	Mon Aug 19 16:08:28 2019 -0700
@@ -183,11 +183,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;
     }
 
     /**