typetools / typetools/checker-framework
Nullable type unnecessarily inferred converting List<? extends T> to List<? extends T>
Open
@wmdietl is already working on this.
Since Dec 16, 2019.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
More from playing around with #2719. This one is only a false positive and might well be a known issue. (I was going to say it could be part of #979, but javac 7 is able to infer that get(0) returns a String, so I would naively expect the Checker Framework to infer that it returns a non-null String.)
import static java.util.Arrays.asList;
import java.util.List;
class Foo {
void foo() {
passThrough(asList("x")).get(0).length();
}
<T> List<? extends T> passThrough(List<? extends T> object) {
return object;
}
}
$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker Foo.java
Foo.java:7: error: [dereference.of.nullable] dereference of possibly-null reference passThrough(asList("x")).get(0)
passThrough(asList("x")).get(0).length();
^
1 error
Interestingly, if I change foo() to the following, then it compiles:
String foo() {
return passThrough(asList("x")).get(0);
}
And of course it also compiles if I pass an explicit <String> argument to either asList or passThrough.
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.
Assessment
This issue has not been assessed yet.