Details
-
Bug
-
Resolution: Fixed
-
P4
-
11, 17, 18, 19, 20
-
b25
-
generic
-
generic
-
Verified
Description
A DESCRIPTION OF THE PROBLEM :
Collections.unmodifiableMap(map).entrySet().iterator().forEachRemaining(action) and Collections.checkedMap(map, keyType, valueType).entrySet().iterator().forEachRemaining(action) are both missing a null check for the action. They wrap the possibly action in a new action, then delegate to the backing iterator. The delegate's null check passes, and the iteration consumes an element before a NullPointerException is thrown by the wrapping action when it tries to invoke the given action.
Both methods should include a null check. In case of the unmodifiable map, the null check can probably be integrated into the entryConsumer method, instead of adding it before calling entryConsumer (which is now done in 3 of the 4 cases).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Call Collections.unmodifiableMap(Map.of()).entrySet().iterator().forEachRemaining(null) and Collections.checkedMap(Map.of(), String.class, String.class).entrySet().iterator().forEachRemaining(null).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A NullPointerException is thrown.
ACTUAL -
Nothing is thrown.
FREQUENCY : always
Collections.unmodifiableMap(map).entrySet().iterator().forEachRemaining(action) and Collections.checkedMap(map, keyType, valueType).entrySet().iterator().forEachRemaining(action) are both missing a null check for the action. They wrap the possibly action in a new action, then delegate to the backing iterator. The delegate's null check passes, and the iteration consumes an element before a NullPointerException is thrown by the wrapping action when it tries to invoke the given action.
Both methods should include a null check. In case of the unmodifiable map, the null check can probably be integrated into the entryConsumer method, instead of adding it before calling entryConsumer (which is now done in 3 of the 4 cases).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Call Collections.unmodifiableMap(Map.of()).entrySet().iterator().forEachRemaining(null) and Collections.checkedMap(Map.of(), String.class, String.class).entrySet().iterator().forEachRemaining(null).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A NullPointerException is thrown.
ACTUAL -
Nothing is thrown.
FREQUENCY : always
Attachments
Issue Links
- relates to
-
JDK-8205184 Delegating Iterator implementations that don't delegate forEachRemaining()
- Resolved