kelloggm / checkerframework-gradle-plugin

Gradle plugin to use the Checker Framework for Java
Apache License 2.0
66 stars 15 forks source link

Run failed on JDK 8 #149

Closed XiaoPangxie732 closed 3 years ago

XiaoPangxie732 commented 3 years ago

System with JDK 11 installed and the following Gradle configuration:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(8)
        vendor = JvmVendorSpec.ADOPTOPENJDK
    }
}

Got this error:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
kelloggm commented 3 years ago

Sorry you're having trouble! I'm having difficulty reproducing the issue you're describing.

I tried adding the code you described to a simple sample Gradle project that uses the plugin; you can find that simple project here: https://github.com/kelloggm/sample-gradle-project/tree/repro-cf-gradle-149. When I run ./gradlew clean build on the project linked above, I get the output:

> Configure project :
Unable to determine Checker Framework version. Assuming default is being used: 3.11.0

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/kelloggm/jsr308/sample-gradle-project/build.gradle' line: 33

* What went wrong:
A problem occurred evaluating root project 'sample-gradle-project'.
> No signature of method: build_22n4gkxop7tl5d7vh5g33jvft.java() is applicable for argument types: (build_22n4gkxop7tl5d7vh5g33jvft$_run_closure3) values: [build_22n4gkxop7tl5d7vh5g33jvft$_run_closure3@62ad181d]
  Possible solutions: wait(), any(), wait(long), tap(groovy.lang.Closure), each(groovy.lang.Closure), any(groovy.lang.Closure)

* 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

This output suggests to me that I didn't reproduce the issue you're describing correctly, since the error message indicates that the build file isn't valid. Can you help me produce a valid build file that exhibits this problem, so that I can fix it?

On a theoretical note, I have some suspicions about what might have caused this bug. Without the ability to reproduce it, I can't test them, so what follows is pure speculation. The error message you're seeing definitely suggests a mismatch between the JVM version and the options being passed to the Checker Framework. The option --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED is passed by the plugin to the JVM in which the Checker Framework will run if the plugin detects that the JVM is Java9-compatible, according to Gradle's API. It seems to me that you're running a Java 11 JVM in a configuration where it's pretending to be a Java 8 JVM, and thus rejecting the option. One possible solution would be to add an option to the plugin that forces it to assume the underlying JVM is a particular version, rather than relying on the Gradle API; that's not particularly elegant, but I think it would let you work around this particular problem.

XiaoPangxie732 commented 3 years ago

I found that you are using Gradle 6.3, the configuration I provided doesn't compatible with Gradle 6.3(toolchain block is an incubating feature added in Gradle 6.8). You could use Gradle 6.8.3 and try again. And make sure you use JDK 11 to run the script.

kelloggm commented 3 years ago

@XiaoPangxie732 Sorry for taking some time to get back to you. I was able to reproduce the failure you see using Gradle 6.8.3 - thanks! I've opened a PR (#152) which I hope will fix the bug.

Since it may take some time to merge that PR and release a new version, I also put up a version 0.5.19-SNAPSHOT that you can use right away to test this on your project. Please let me know if you do and it works (or not!).

XiaoPangxie732 commented 3 years ago

Thanks. It works.