8166842: String.hashCode() has a non-benign data race
Reviewed-by: shade, alanb, martin
--- 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;
}
/**