[concurrency-interest] Does JDK 9 String.hashCode() have a bug?

Aleksey Shipilev shade at redhat.com
Wed Sep 28 06:38:29 EDT 2016


Hi Peter,

On 09/28/2016 12:33 PM, Peter Levart wrote:
>     public int hashCode() {
>         if (hash == 0 && value.length > 0) {
>             hash = isLatin1() ? StringLatin1.hashCode(value)
>                               : StringUTF16.hashCode(value);
>         }
>         return hash;
>     }

Yes, this is a non-benign data race: should not do the second racy read
at "return hash". Embarrassing that we've missed this during code
reviews. Submit a bug/patch?

Thanks,
-Aleksey

P.S. Your explanation is similar to a more detailed of mine here:

https://shipilev.net/blog/2016/close-encounters-of-jmm-kind/#wishful-benign-is-resilient

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20160928/48e704c6/attachment.sig>


More information about the Concurrency-interest mailing list