checker-framework
checker-framework copied to clipboard
Field with @RequiresNonNull + @MonotonicNonNull is treated as nullable inside lambda
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
class Require {
@MonotonicNonNull String s;
@RequiresNonNull("s")
Supplier<String> s() {
return () -> s;
}
interface Supplier<T> {
T get();
}
}
Actual:
$ ./checker-framework-3.43.0/checker/bin/javac -processor nullness Require.java
Require.java:9: error: [return] incompatible types in return.
return () -> s;
^
type of expression: @Initialized @MonotonicNonNull String
method return type: @Initialized @NonNull String
1 error
Expected:
No error: Even though the lambda may run later, s
is not only known to be non-null initially but is also known to remain so because of @MonotonicNonNull
.