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).

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

Commit messages:
 - Fix WeakHashMap in IteratorAtEnd

Changes: https://git.openjdk.org/valhalla/pull/2509/files
  Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=2509&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8375563
  Stats: 11 lines in 1 file changed: 9 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/valhalla/pull/2509.diff
  Fetch: git fetch https://git.openjdk.org/valhalla.git pull/2509/head:pull/2509

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

Reply via email to