8304591: (fs) UnixPath.stringValue need not be volatile

Reviewed-by: alanb, bpb, shade
This commit is contained in:
Sergey Tsypanov 2023-03-28 11:14:09 +00:00 committed by Alan Bateman
parent 60640a216d
commit 395a4ce0dd

@ -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;
}