changeset 15752:19736467290a

8166842: String.hashCode() has a non-benign data race Reviewed-by: shade, alanb, martin
author plevart
date Fri, 30 Sep 2016 17:34:08 +0200
parents 64d3579d3ebc
children 4dbeb5b87d67 2eb1e7d6e509
files src/java.base/share/classes/java/lang/String.java
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/String.java	Fri Sep 30 17:05:54 2016 +0300
+++ b/src/java.base/share/classes/java/lang/String.java	Fri Sep 30 17:34:08 2016 +0200
@@ -1516,11 +1516,12 @@
      * @return  a hash code value for this object.
      */
     public int hashCode() {
-        if (hash == 0 && value.length > 0) {
-            hash = isLatin1() ? StringLatin1.hashCode(value)
-                              : StringUTF16.hashCode(value);
+        int h = hash;
+        if (h == 0 && value.length > 0) {
+            hash = h = isLatin1() ? StringLatin1.hashCode(value)
+                                  : StringUTF16.hashCode(value);
         }
-        return hash;
+        return h;
     }
 
     /**