8166842: String.hashCode() has a non-benign data race
authorplevart
Fri, 30 Sep 2016 17:34:08 +0200
changeset 41219 eab7a5086e95
parent 41218 c22c646e063c
child 41220 ebb2fec04e82
child 41405 0d3b7bc68b7d
8166842: String.hashCode() has a non-benign data race Reviewed-by: shade, alanb, martin
jdk/src/java.base/share/classes/java/lang/String.java
--- a/jdk/src/java.base/share/classes/java/lang/String.java	Fri Sep 30 17:05:54 2016 +0300
+++ b/jdk/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;
     }
 
     /**