8229899: Make java.io.File.isInvalid() less racy
Reviewed-by: alanb, martin, shade
--- 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;
}
/**