-
Notifications
You must be signed in to change notification settings - Fork 435
Open
Description
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 Test.java
File
import org.checkerframework.checker.nullness.qual.*;
import java.util.*;
public class Test {
public static <T> T m(List<T> lst) { return lst.get(0); }
public static void main(String[] args) {
List<@Nullable Integer> lst = new LinkedList<>();
lst.add(null);
int y = ((true) ? Test.<@Nullable Integer>m(lst) : 10);
}
}Actual behavior
The code passes the checks, but there's NPE
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "Test.m(java.util.List)" is null
at Test.main(Test.java:12)
Expected behavior
The code should have been rejected with
Test.java:12: error: [unboxing.of.nullable] unboxing a possibly-null reference Test.<@Nullable Integer>m(lst)
int y = ((true) ? Test.<@Nullable Integer>m(lst) : 10);
^
1 error
Reactions are currently unavailable