-
Bug
-
Resolution: Fixed
-
P4
-
8, 11, 17, 21
-
b25
-
generic
-
generic
-
Verified
A DESCRIPTION OF THE PROBLEM :
The `Map.merge` method of the map created by `Collections.checkedMap` (and related factory methods) does not check the key and value type when no entry exists yet.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code provided below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The `merge` call should fail with a ClassCastException because both the key and value type are incorrect.
ACTUAL -
No exception is thrown and the invalid key and value are added to the map.
---------- BEGIN SOURCE ----------
Map m = Collections.checkedMap(new HashMap<>(), Integer.class, Integer.class);
m.merge("key", "value", (v1, v2) -> null);
---------- END SOURCE ----------
FREQUENCY : always
The `Map.merge` method of the map created by `Collections.checkedMap` (and related factory methods) does not check the key and value type when no entry exists yet.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code provided below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The `merge` call should fail with a ClassCastException because both the key and value type are incorrect.
ACTUAL -
No exception is thrown and the invalid key and value are added to the map.
---------- BEGIN SOURCE ----------
Map m = Collections.checkedMap(new HashMap<>(), Integer.class, Integer.class);
m.merge("key", "value", (v1, v2) -> null);
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8029055 Map.merge must refuse null values
- Closed