typetools / typetools/checker-framework
Nullness checker handling of implicit type variable bounds - difference between <T> and <T extends @Nullable Object>
Open
@smillst is already working on this.
Since Jan 1, 2023.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
In the following example, the nullness checker rejects an input that contains a type variable with an explicit extends @Nullable Object bound, and accepts the same example if the explicit bound is removed.
The CLIMB-to-top defaults say implicit type variable bounds are interpreted as equivalent extends @Nullable Object, is this a bug?
import org.checkerframework.checker.nullness.qual.Nullable;
class A<V extends @Nullable Object> {
I<V> i() {
return new B<>(this);
}
}
class B<K, V> implements I<V> {
B(A<V> a) {}
}
interface I<V> {}
With Checker Framework 3.21.3:
$ ./checker-framework-3.21.3/checker/bin/javac -processor nullness A.java
A.java:5: error: [return] incompatible types in return.
return new B<>(this);
^
type of expression: @Initialized @NonNull B<@Initialized @NonNull Object, V extends @Initialized @NonNull Object>
method return type: @Initialized @NonNull I<V extends @Initialized @Nullable Object>
A.java:5: error: [argument] incompatible argument for parameter a of B.
return new B<>(this);
^
found : @Initialized @NonNull A<V extends @Initialized @Nullable Object>
required: @Initialized @NonNull A<V extends @Initialized @NonNull Object>
2 errors
The code compiles without error if extends @Nullable Object is removed.
diff A.java B.java
3c3
< class A<V extends @Nullable Object> {
---
> class A<V> {
$ ./checker-framework-3.21.3/checker/bin/javac -processor nullness B.java
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.