tbroyer / gradle-errorprone-plugin

Gradle plugin to use the error-prone compiler for Java
Apache License 2.0
366 stars 32 forks source link

Fix Java 16 bug when using TimeZone class #58

Closed dcabasson closed 3 years ago

dcabasson commented 3 years ago

The provided test fails under Java 16 without the addition of --add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED

> Task :compileJava FAILED
/private/var/folders/jf/29g0fz_16w9_3y2db8ylkl540000gn/T/junit1380605189140352106/src/main/java/test/TimeZoneJava16.java:7: error: An unhandled exception was thrown by the Error Prone static analysis plugin.
        return TimeZone.getTimeZone("PST");
                                   ^
     Please report this at https://github.com/google/error-prone/issues/new and include the following:

     error-prone version: 2.5.1
     BugPattern: ThreeLetterTimeZoneID
     Stack Trace:
     java.lang.IllegalAccessError: class com.google.errorprone.VisitorState (in unnamed module @0x51b6b93c) cannot access class com.sun.tools.javac.model.JavacElements (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.model to unnamed module @0x51b6b93c
    at com.google.errorprone.VisitorState.getElements(VisitorState.java:244)
    at com.google.errorprone.bugpatterns.ThreeLetterTimeZoneID.matchMethodInvocation(ThreeLetterTimeZoneID.java:79)
    at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:450)
tbroyer commented 3 years ago

Thanks for the report (and patch).

Would you mind opening an issue on Error prone itself to get the doc fixed for non-Gradle users too: http://errorprone.info/docs/installation ?

I'll take some time before merging this to try to find other similar cases.

dcabasson commented 3 years ago

Salut Thomas!

Unfortunately because of restrictions from my employer, I cannot open an issue on the errorprone project itself. While I am allowed to contribute fixes to this project that we are using, I have not been authorized to interact with other projects.

Sorry about that.

tbroyer commented 3 years ago

I just released v2.0.1 with the fix (using --add-exports rather than --add-opens as it's enough). I confirmed the change works using your provided test, but didn't include it as the list of flags follows what the ErrorProne doc says.