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 com.sun.tools.javac.util #1079

Open
rikintanna opened this issue Mar 6, 2024 · 2 comments
Open

IllegalAccessError from com.sun.tools.javac.util #1079

rikintanna opened this issue Mar 6, 2024 · 2 comments
Labels

Comments

@rikintanna
Copy link

rikintanna commented Mar 6, 2024

Similar to #787 (comment)_

Caused by: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.RemoveUnusedImports (in unnamed module @0x2b099be2) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x2b099be2 at com.google.googlejavaformat.java.RemoveUnusedImports.removeUnusedImports(RemoveUnusedImports.java:218) ... 142 more

This issue occurs when building at command line and in Intellij.

I tried adding the below workaround to my gradle.properties file

org.gradle.jvmargs=-Xms2g -Xmx8g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 \
  --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
  --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
  --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

java version

✗ java -version
openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment Homebrew (build 17.0.10+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.10+0, mixed mode, sharing)

Originally posted by @rikintanna in #787 (comment)

@rikintanna rikintanna changed the title seeing a similar problem with a different module in googlejavaformat library IllegalAccessError from com.sun.tools.javac.util Mar 6, 2024
@cushon cushon added the IntelliJ label Mar 6, 2024
@rikintanna rikintanna reopened this Mar 11, 2024
@romani
Copy link

romani commented Jul 10, 2024

@cushon , can you consider to remove label "Intelij" ?

this problem is for maven projects when formatter is used as library , so it is problem for all users of jdk17.

java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x459e9125) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x459e9125

we have problems with it at checkstyle/checkstyle#15222 (comment) , failure is on MacOS container with JDK17.

some workaround for maven users is at https://github.com/Cosium/git-code-format-maven-plugin?tab=readme-ov-file#jdk-16-peculiarities

@cushon
Copy link
Collaborator

cushon commented Jul 10, 2024

@romani there's some documentation about this here: https://github.com/google/google-java-format?tab=readme-ov-file#as-a-library, the --add-exports= flags are required when using google-java-format as a library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants