typetools / typetools/checker-framework

NullnessChecker (w/ Android Gradle) cannot find generated AutoValue classes.

Open
#4,232 6 comments 0 reactions 1 assignee View on GitHub

@smillst is already working on this.

Since Feb 25, 2021.

Unreproducible
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

As explained in the instructions for submitting an issue at https://checkerframework.org/manual/#reporting-bugs:

  • commands: ./gradlew assembleChecked or ./gradlew lint
  • inputs N/A
  • outputs:
➜  MyApplication2 $ ./gradlew lint                            

> Task :app:compileCheckedJavaWithJavac
The following annotation processors are not incremental: org.checkerframework.checker.nullness.NullnessChecker.
Make sure all annotation processors are incremental to improve your build speed.
/Users/me/AndroidStudioProjects/MyApplication2/app/src/main/java/com/example/myapplication/MainActivity.java:21: error: cannot find symbol
            return new AutoValue_MainActivity_Foo();
                       ^
  symbol:   class AutoValue_MainActivity_Foo
  location: class Foo
1 error

> Task :app:compileCheckedJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileCheckedJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s
12 actionable tasks: 1 executed, 11 up-to-date
  • expectation BUILD SUCCESSFUL...

I'm adding the NullnessChecker to my project and am running in to this issue for every AutoValue class whose generated code is referenced. To isolate the issue I created a new Android Studio project with the "EmptyActivity" template, added a @AutoValue class Foo to MainActivity and followed https://checkerframework.org/manual/#android-gradle. ie. my only changes are:

build.gradle:

android {
    buildTypes {
        checked {
            initWith debug
            applicationIdSuffix ".checked"

            javaCompileOptions.annotationProcessorOptions {
                classNames.add("org.checkerframework.checker.nullness.NullnessChecker")
                arguments.put("nocheckjdk", "")
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
dependencies {
    implementation "org.checkerframework:checker-qual-android:3.10.0"
    annotationProcessor "org.checkerframework:checker:3.10.0"
    implementation "com.google.auto.value:auto-value-annotations:1.7.4"
    annotationProcessor "com.google.auto.value:auto-value:1.7.4"
}

and MainActivity:

public class MainActivity extends AppCompatActivity {
    ...
    @AutoValue
    static abstract class Foo {
        static Foo create() {
            return new AutoValue_MainActivity_Foo();
        }
    }
}

Without the NullnessChecker everything runs fine (ie. the checker passes & errors as expected). I can remove the AutoValue class and everything also runs fine. I can also change the NullnessChecker to some other Checker like "org.checkerframework.checker.interning.InterningChecker" and repro the same issue. Mainly I haven't been able to find a solution googling so far.

➜  MyApplication2 $ java -version
java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)
➜  MyApplication2 $ javac -version
javac 11.0.9

Lastly, when run from AndroidStudio (ie. Build > Rebuild Project) I get multiple errors:

failed
:app:compileCheckedJavaWithJavac
    app/src/main/java/com/example/myapplication/MainActivity.java
            cannot find symbol class AutoValue_MainActivity_Foo
        Error when invoking constructor for class org.checkerframework.checker.nullness.KeyForAnnotatedTypeFactory on args [org.checkerframework.checker.nullness.KeyForSubchecker@483570e8]; parameter types: [class org.checkerframework.common.basetype.BaseTypeChecker]; cause: java.lang.NoSuchFieldError: RELEASE
        java.lang.NullPointerException
    Cause: java.lang.NullPointerException

Any help would be greatly appreciated.
Thanks in advance!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.