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 1fe4a13854b62..a614f5025f283 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 @@ public int hashCode() { @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; }