Feature Request - detect key of wrong type passed to Map.get() or Map.remove()
See original GitHub issueSince the signature of these methods, by design, does not constrict you to use the generic type of the key, and is just Object
, it is easy to accidentally pass the wrong variable.
This is especially true for remove(), which in the case of cache clean-up code, might not have full test coverage, or missing/difficult to assert behaviour. This has been seen to lead to leaked memory.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
What are the reasons why Map.get(Object key) is not (fully ...
TreeMap may fail when you pass objects of the wrong type to the get method but may pass occasionally, e.g. when the map...
Read more >335953 – No warning for wrongly typed map get - Bugs - Eclipse
Map.get(Object) where V is the type variable for the key. ... you try to get() from the Map with a wrong key type,...
Read more >Map and Set - The Modern JavaScript Tutorial
map.has(key) – returns true if the key exists, false otherwise. map.delete(key) – removes the element (the key/value pair) by the key. map.clear ...
Read more >How to Handle the Incompatible Types Error in Java - Rollbar
The Java incompatible types error happens when a value assigned to a variable or returned by a method is incompatible with the one...
Read more >Map (Java Platform SE 8 ) - Oracle Help Center
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This sounds like what the
CollectionIncompatibleType
check (source) already does. Is that what you’re looking for?ok, wow! IntelliJ’s inspection is not so generous or conservative depending on your view point.
maybe there could be an experimental version of the rule that was “stricter”?
Or, maybe a warning type rule for using non-final types as keys?