google / error-prone

Catch common Java mistakes as compile-time errors
https://errorprone.info
Apache License 2.0
6.86k stars 744 forks source link

Var false possitives detected when NPE (via nullaway) detected #4305

Open xenoterracide opened 8 months ago

xenoterracide commented 8 months ago

maybe this is an issue with nullaway, I'll cross report. None of these @Var's are not effectively final. this.git is variable though.

Full source here https://github.com/xenoterracide/gradle-semver/blob/external/bug/ep/buildSrc/src/main/kotlin/our.javacompile.gradle.kts

/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/AbstractGitService.java:28: error: [NullAway] dereferenced expression this.git is @Nullable
    this.git.checkout();
            ^

> Task :compileJava
    (see http://t.uber.com/nullaway )
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:15: error: [Var] Non-constant variable missing @Var annotation
  DelegatingSystemReader(SystemReader reader) {
                                      ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'DelegatingSystemReader(@Var SystemReader reader) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:25: error: [Var] Non-constant variable missing @Var annotation
  public String getenv(String variable) {
                              ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public String getenv(@Var String variable) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:30: error: [Var] Non-constant variable missing @Var annotation
  public String getProperty(String key) {
                                   ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public String getProperty(@Var String key) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:35: error: [Var] Non-constant variable missing @Var annotation
  public FileBasedConfig openUserConfig(Config parent, FS fs) {
                                               ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public FileBasedConfig openUserConfig(@Var Config parent, FS fs) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:35: error: [Var] Non-constant variable missing @Var annotation
  public FileBasedConfig openUserConfig(Config parent, FS fs) {
                                                          ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public FileBasedConfig openUserConfig(Config parent, @Var FS fs) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:[40](https://github.com/xenoterracide/gradle-semver/actions/runs/8065969734/job/22032976374#step:4:41): error: [Var] Non-constant variable missing @Var annotation
  public FileBasedConfig openSystemConfig(Config parent, FS fs) {
                                                 ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public FileBasedConfig openSystemConfig(@Var Config parent, FS fs) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:40: error: [Var] Non-constant variable missing @Var annotation
  public FileBasedConfig openSystemConfig(Config parent, FS fs) {
                                                            ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public FileBasedConfig openSystemConfig(Config parent, @Var FS fs) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:[45](https://github.com/xenoterracide/gradle-semver/actions/runs/8065969734/job/22032976374#step:4:46): error: [Var] Non-constant variable missing @Var annotation
  public FileBasedConfig openJGitConfig(Config parent, FS fs) {
                                               ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public FileBasedConfig openJGitConfig(@Var Config parent, FS fs) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:45: error: [Var] Non-constant variable missing @Var annotation
  public FileBasedConfig openJGitConfig(Config parent, FS fs) {
                                                          ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public FileBasedConfig openJGitConfig(Config parent, @Var FS fs) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/DelegatingSystemReader.java:[55](https://github.com/xenoterracide/gradle-semver/actions/runs/8065969734/job/22032976374#step:4:56): error: [Var] Non-constant variable missing @Var annotation
  public int getTimezone(long when) {
                              ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public int getTimezone(@Var long when) {'?
/home/runner/work/gradle-semver/gradle-semver/src/main/java/com/xenoterracide/gradle/semver/ExceptionTools.java:10: error: [Var] Non-constant variable missing @Var annotation
  static RuntimeException rethrow(Throwable e) {
                                            ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'static RuntimeException rethrow(@Var Throwable e) {'?
aopalliance:aopalliance:1.0=annotationProcessor,errorprone,testAnnotationProcessor
com.github.ben-manes.caffeine:caffeine:3.0.5=annotationProcessor,errorprone,testAnnotationProcessor
com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor,errorprone,testAnnotationProcessor
com.google.auto.service:auto-service-annotations:1.0.1=annotationProcessor,errorprone,testAnnotationProcessor
com.google.auto.value:auto-value-annotations:1.9=annotationProcessor,errorprone,testAnnotationProcessor
com.google.auto:auto-common:1.2.2=annotationProcessor,errorprone,testAnnotationProcessor
com.google.code.findbugs:jsr305:3.0.2=annotationProcessor,checkstyle,compileClasspath,errorprone,spotbugs,spotless1659553931,testAnnotationProcessor,testCompileClasspath
com.google.errorprone:error_prone_annotation:2.25.0=annotationProcessor,errorprone,testAnnotationProcessor
com.google.errorprone:error_prone_annotations:2.25.0=annotationProcessor,compileClasspath,errorprone,testAnnotationProcessor
com.google.errorprone:error_prone_check_api:2.25.0=annotationProcessor,errorprone,testAnnotationProcessor
com.google.errorprone:error_prone_core:2.25.0=annotationProcessor,errorprone,testAnnotationProcessor
com.google.errorprone:error_prone_type_annotations:2.25.0=annotationProcessor,errorprone,testAnnotationProcessor
com.google.guava:failureaccess:1.0.1=annotationProcessor,checkstyle,errorprone,spotless1659553931,testAnnotationProcessor
com.google.guava:guava-parent:32.1.1-jre=annotationProcessor,errorprone,testAnnotationProcessor
com.google.guava:guava:32.1.1-jre=annotationProcessor,errorprone,testAnnotationProcessor
com.google.inject:guice:5.1.0=annotationProcessor,errorprone,testAnnotationProcessor
com.google.protobuf:protobuf-java:3.19.6=annotationProcessor,errorprone,testAnnotationProcessor
com.uber.nullaway:nullaway:0.10.23=annotationProcessor,errorprone,testAnnotationProcessor
io.github.eisop:dataflow-errorprone:3.41.0-eisop1=annotationProcessor,errorprone,testAnnotationProcessor
io.github.java-diff-utils:java-diff-utils:4.12=annotationProcessor,errorprone,spotless1659553931,testAnnotationProcessor
javax.inject:javax.inject:1=annotationProcessor,errorprone,testAnnotationProcessor
org.checkerframework:checker-qual:3.33.0=annotationProcessor,errorprone,testAnnotationProcessor
org.checkerframework:dataflow-nullaway:3.40.0=annotationProcessor,errorprone,testAnnotationProcessor
org.pcollections:pcollections:4.0.1=annotationProcessor,errorprone,testAnnotationProcessor
XN137 commented 1 month ago

this might be the same problem as described in https://github.com/google/error-prone/issues/4595 wdyt ?

xenoterracide commented 1 month ago

@XN137 possible, symptoms sound the same. I suppose you could write some tests that add nullaway and see if you get the same result.

cushon commented 1 month ago

I think I understand what's happening in #4595, @xenoterracide if you get a chance could you try adding -XDshould-stop.ifError=FLOW to this build and see if the false positives go away?

xenoterracide commented 3 weeks ago

I'll try to get around to this soon, sorry I haven't yet. Looks like the most recent version of nullaway has a regression in some of my code https://github.com/uber/NullAway/issues/1059