On Thu, 4 Jun 2026 02:52:31 GMT, Chen Liang <[email protected]> wrote:

> IteratorAtEnd spuriously failed for `WeakHashMap`. The underlying cause is 
> that with the migration of keys to `String` produced by concatenation, these 
> strings may be eagerly garbage collected, leaving the `WeakHashMap` and its 
> collection views empty, causing their `Iterator` to throw 
> `IllegalStateException` for a call to `remove()` because it never returned 
> any entry ever.
> 
> The original failure could be reliably reproduced by adding a `System.gc()` 
> call right after the Map put for loop. I added an assert to prevent such 
> empty iterator to have a confusing error again, and made the keys strongly 
> referenced in a collection to avoid this immediate issue.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

This pull request has now been integrated.

Changeset: 0639bc3b
Author:    Chen Liang <[email protected]>
URL:       
https://git.openjdk.org/valhalla/commit/0639bc3bfd0e8fced795d78995996ce8097948a6
Stats:     11 lines in 1 file changed: 9 ins; 0 del; 2 mod

8375563: [lworld] java/util/Collection/IteratorAtEnd.java fails with 
IllegalStateException

Reviewed-by: aboldtch

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

PR: https://git.openjdk.org/valhalla/pull/2509

Reply via email to