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

IllegalAccessError from ThreeLetterTimeZoneID with JDK 16 #2250

Closed
tbroyer opened this issue Mar 24, 2021 · 1 comment
Closed

IllegalAccessError from ThreeLetterTimeZoneID with JDK 16 #2250

tbroyer opened this issue Mar 24, 2021 · 1 comment

Comments

@tbroyer
Copy link
Contributor

tbroyer commented Mar 24, 2021

Description of the problem / feature request:

> 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)

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

See tbroyer/gradle-errorprone-plugin#58

--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED fixes it.

Could there be an automated way of finding out all those cases? From the unit tests exercising all the bug patterns maybe?

What version of Error Prone are you using?

2.5.1

Have you found anything relevant by searching the web?

Related to #1157

@tbroyer
Copy link
Contributor Author

tbroyer commented Mar 24, 2021

Playing with grep reveals that this could be the only missing bit; also --add-exports might be enough:

$ git grep -h  '^import com.sun.*' |grep -o 'com.sun.[a-z.]*' |sort -u
com.sun.source.doctree.
com.sun.source.tree.
com.sun.source.util.
com.sun.tools.javac.api.
com.sun.tools.javac.code.
com.sun.tools.javac.comp.
com.sun.tools.javac.file.
com.sun.tools.javac.main.
com.sun.tools.javac.model.
com.sun.tools.javac.parser.
com.sun.tools.javac.processing.
com.sun.tools.javac.tree.
com.sun.tools.javac.util.

(where com.sun.source.{doctree,tree,util} are already exported: https://docs.oracle.com/en/java/javase/16/docs/api/jdk.compiler/module-summary.html)
BTW, how about sorting the options in the docs to make comparison easier? 😉

I also note that the doc suggests both --add-opens and -add-exports for com.sun.tools.javac.code. IIUC, --add-opens is a superset of --add-exports so --add-opens alone would be enough.

@cushon cushon closed this as completed in f200bb1 Mar 25, 2021
tbroyer added a commit to tbroyer/gradle-errorprone-plugin that referenced this issue Mar 26, 2021
Also sort the flags, and just use add-opens for 'comp'.

See google/error-prone#2250
Closes #58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant