Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false negative when encountering recursive bound #6815

Open
theosotr opened this issue Sep 24, 2024 · 1 comment
Open

false negative when encountering recursive bound #6815

theosotr opened this issue Sep 24, 2024 · 1 comment

Comments

@theosotr
Copy link

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.*;


class A<T> {
    public static <T extends Comparable<? super T>> A<T> m(T k) {
        k.toString();
        return new A<T>();
    }
}

public class Test {
    public static void main(String[] args) {
        A.m(null);
    }
}

Actual behavior

The code passes the checks but there's a NPE at runtime

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.toString()" because "<parameter1>" is null
        at A.m(Test.java:6)
        at Test.main(Test.java:13)

Expected behavior

The code should have been rejected.

@smillst
Copy link
Member

smillst commented Sep 24, 2024

Thanks for reporting!

The bug seems to be with the special handling of the null literal in the type argument inference algorithm:

import org.checkerframework.checker.nullness.qual.Nullable;

class Issue6815<T> {
     static <T extends Comparable<? super T>> Issue6815<T> m(T k) {
      k.toString();
      return new Issue6815<T>();
    }
    void method1(@Nullable Integer i) {
      Issue6815.m(i);  // true positive
    }
    void method2() {
      Issue6815.m(null);  // false negative
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants