On Thu, 3 Dec 2026 03:30:41 GMT, Daisuke Yamazaki <[email protected]> wrote:

>> Please review this fix for `Set.ofLazy` and `Map.ofLazy` behaviour.
>> 
>> When looking up an object that is equal to a stored candidate but is a 
>> different instance,
>> `Set.contains()` and `Map.get()` pass the lookup argument to the computing 
>> function instead of the stored candidate.
>> 
>> This change stores the candidates in an array and uses the lookup index to 
>> retrieve the corresponding candidate before calling the computing function.
>> 
>> Regression tests have been added for both `Set` and `Map` to verify that the 
>> computing function receives the stored candidate.
>> 
>> Tests:
>> - `LazySetTest`
>> - `tier1`
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Daisuke Yamazaki has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   review

I like the direction this PR is taking!

I think we should also point out which element is used in the specification. 
Something along the lines "the callback receives the original key or candidate, 
even when an equal object triggers initialization". This would mean we would 
need a CSR.

src/java.base/share/classes/java/util/LazyCollections.java line 239:

> 237: 
> 238:             @Override
> 239:             public int findSlot(Object key) { return 
> this.key.equals(key) ? 0 : -1; }

I think we could use `key.equals(this.key)` so we will get the same order as in 
Map1?

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

PR Comment: https://git.openjdk.org/jdk/pull/34144#issuecomment-7374794595
PR Review Comment: https://git.openjdk.org/jdk/pull/34144#discussion_r4783019092

Reply via email to