RFR: 8292955: Collections.checkedMap Map.merge does not properly check key and value [v2]

Korov duke at openjdk.org
Thu Mar 7 05:35:53 UTC 2024


On Thu, 7 Mar 2024 04:37:24 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Korov has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   modify the code based on the review
>
> test/jdk/java/util/Collections/CheckedMapBash.java line 193:
> 
>> 191:             m.merge("key", "value", (v1, v2) -> null);
>> 192:             fail("Should throw ClassCastException");
>> 193:         } catch (ClassCastException ignore) {
> 
> Since this test is already running with testNG, we should just use its builtin functionalities:
> 
>     @Test(groups = "type_check")
>     public static void testTypeCheck() {
>         Map m = Collections.checkedMap(new HashMap<>(), Integer.class, Integer.class);
>         Assert.assertThrows(ClassCastException.class, () -> m.merge("key", "value", (v1, v2) -> null));
>         Assert.assertThrows(ClassCastException.class, () -> m.merge("key", 3, (v1, v2) -> v2));
>     }
> 
> 
> In addition, the checked map tests are in general, only checking the map functionality works without checking if the type checking functionality works. But adding a comprehensive test for checking functionalites would be much more work and is out of this patch's scope, so you don't need to worry about it.

Thank you very much for informing me about these things. I have modified the test function name.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18141#discussion_r1515562837


More information about the core-libs-dev mailing list