Results of keys is always false

Answered

Hi there,

one question: I created the following test case in Java:

Map<String, Integer> testMap = new HashMap<>();
Set<String> keys = testMap.keySet(); // keys is a view on the map
Assertions.assertTrue(keys.isEmpty());

testMap.put("a", 1);
Assertions.assertTrue(keys.contains("a"));

IntelliJ IDEA recommends me, to change 'keys.contains("a")' in the last row to 'false' "Result of 'keys.contains("a")' is always 'false' ". However, because the keys variable is a view on the keyset of the map, the assertion in this test do not throw an error (which is correct).

 

IDEA version 2021.1

0
1 comment

Hello,

Please follow the issue created in the YouTrack for your case: https://youtrack.jetbrains.com/issue/IDEA-268907

Thank you for the report!

0

Please sign in to leave a comment.