[lworld] RFR: 8366214: [lworld] Use Objects.equals in HashMap and ConcurrentHashmap

Chen Liang liach at openjdk.org
Thu Aug 28 13:41:59 UTC 2025


On Thu, 28 Aug 2025 13:32:26 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java line 682:
>> 
>>> 680:                     K ek;
>>> 681:                     if (e.hash == h &&
>>> 682:                         (ek = e.key) != null && Objects.equals(k, ek))
>> 
>> Looking at the code in HashMap, I think you can just use `Objects.equals(k, ek = e.key)`, or just `k.equals(ek = e.key)` because `Object::equals` is supposed to return false on null.
>
> HashMap allows null keys and that is handled separately in each case, not by the `equals` method.
> "supposed to" is not sufficient when compatibility is concerned.

I think your current logic differs when `e.key == null` and `k == null` - previously it evaluates to true, now this test fails.

-------------

PR Review Comment: https://git.openjdk.org/valhalla/pull/1536#discussion_r2307452667


More information about the valhalla-dev mailing list