Command
javac -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
-processor org.checkerframework.checker.nullness.NullnessChecker \
-cp checker-framework/checker/dist/checker.jar -Aignorejdkastub Test.java
File
import java.util.*;
import org.checkerframework.checker.nullness.qual.*;
class A<T> {
T f;
A(T f) {this.f = f;}
T getF() { return this.f; }
}
public class Test {
static public void main(String[] args) {
Map<@Nullable String, String> map = new HashMap<@Nullable String, String>();
map.put(null, "");
A<Map<@Nullable String, String>> x = new A<Map<@Nullable String, String>>(map);
Map<String, ?> y = x.getF();
y.keySet().iterator().next().toString();
}
}
Actual behavior
The code passes the check, but there's a NPE
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.toString()" because the return value of "java.util.Iterator.next()" is null
at Test.main(Test.java:17)
Expected behavior
The code should have been rejected
Test.java:16: error: [assignment] incompatible types in assignment.
Map<String, ?> y = x.getF(); // invalid assignment
^
Command
File
Actual behavior
The code passes the check, but there's a NPE
Expected behavior
The code should have been rejected