Skip to content

Commit

Permalink
8304591: (fs) UnixPath.stringValue need not be volatile
Browse files Browse the repository at this point in the history
Reviewed-by: alanb, bpb, shade
  • Loading branch information
Sergey Tsypanov authored and Alan Bateman committed Mar 28, 2023
1 parent 60640a2 commit 395a4ce
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions 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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

1 comment on commit 395a4ce

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.