typetools / typetools/checker-framework
Java collection methods that accept Object should consider type hierarchy
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
The ErrorProne check Incompatible type as argument to Object-accepting Java collections method ensures that methods like Collection.contains take an argument of the right type.
It would be useful to extend this check to be aware of the type hierarchy of a particular checker.
For example, from #1999:
private final Map<String, String> map;
public @Nullable String get(@Nullable String key) {
return map.get(key);
}
Map.get is declared to take a @Nullable Object and therefore the above code passes the Nullness Checker.
However, allowing null isn't useful, as the key type of map is @NonNull String.
It would be useful, for all type systems, if there were at least a warning about such incorrect usage.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CollectionIncompatibleType check and the example from #1999, including the Nullness Checker and Map.get behavior. Determine how checker-specific type hierarchies should affect Object-accepting collection methods across type systems; the work is done when incompatible uses such as a nullable key with a non-null String key type produce an appropriate warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100