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 One thing I discovered in my prototype was that it would be good to "freeze" the backing Set if the initial set is indeed lazy itself. Otherwise the iteration order might differ depending on if the underlying map's `get()` operation has been called or not. Here is a reproducer of that problem: var entries = Map.ofLazy(Set.of("x"), Function.identity()).entrySet(); var outer = Map.ofLazy(entries, Function.identity()); outer.get(Map.entry("x", "x")); outer.forEach((key, value) -> assertSame(key, value)); So, with get there, I think the current PR test will fail. If get is removed, it seams it would pass. I had this in my prototype: if (keys instanceof AbstractLazyMap.LazyMapEntrySet<?, ?> lazyKeys) { keys = Set.of(lazyKeys.toArray(LazyCollections::<K>newGenericArray)); } Maybe there is a better solution to this? ------------- PR Comment: https://git.openjdk.org/jdk/pull/34144#issuecomment-7375317867
