From 395a4ce0dd4181bbb4bc0888038309901ebf8fea Mon Sep 17 00:00:00 2001 From: Sergey Tsypanov Date: Tue, 28 Mar 2023 11:14:09 +0000 Subject: [PATCH] 8304591: (fs) UnixPath.stringValue need not be volatile Reviewed-by: alanb, bpb, shade --- src/java.base/unix/classes/sun/nio/fs/UnixPath.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixPath.java b/src/java.base/unix/classes/sun/nio/fs/UnixPath.java index 1fe4a13854b..a614f5025f2 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixPath.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixPath.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -57,8 +57,8 @@ class UnixPath implements Path { // internal representation private final byte[] path; - // String representation (created lazily) - private volatile String stringValue; + // String representation (created lazily, no need to be volatile) + private String stringValue; // cached hashcode (created lazily, no need to be volatile) private int hash; @@ -761,8 +761,9 @@ class UnixPath implements Path { @Override public String toString() { // OK if two or more threads create a String + String stringValue = this.stringValue; if (stringValue == null) { - stringValue = fs.normalizeJavaPath(Util.toString(path)); // platform encoding + this.stringValue = stringValue = fs.normalizeJavaPath(Util.toString(path)); // platform encoding } return stringValue; }