[BUG]Collections.unmodifiableMap(map).entrySet().iterator().forEachRemaining ismissing null check
Rob Spoor
openjdk at icemanx.nl
Fri Aug 12 14:05:16 UTC 2022
I found one similar issue, https://bugs.openjdk.org/browse/JDK-8015008,
but that was for an empty primitive iterator. I've created a bug report
with id 9073784.
On 11/08/2022 01:24, some-java-user-99206970363698485155 at vodafonemail.de
wrote:
> Hi,
> could you please report this at https://bugreport.java.com/bugreport/
> (please also first search at https://bugs.openjdk.org/issues?jql=project%3DJDK%20AND%20issuetype%3DBug
> whether it has already been reported).
>
> This also seems to affect the `CheckedEntrySet`; would be good if you could mention that
> in your report as well.
>
> I think the easiest reproducers for this can be created with an empty map:
> ```
> Collections.unmodifiableMap(Map.of()).entrySet().iterator().forEachRemaining(null)
> Collections.checkedMap(Map.of(), String.class, String.class).entrySet().iterator().forEachRemaining(null)
> ```
> Per specification both calls should throw a NullPointerException, but they don't throw it.
>
> Might also be worth recommending to the JDK authors to perform the null check in the internal
> `entryConsumer` method to avoid having it repeated 4 times, once for each caller. The `CheckedEntrySet`
> would still need a separate null check though.
>
> Kind regards
>
More information about the core-libs-dev
mailing list