palantir-java-format
palantir-java-format copied to clipboard
jdk.compiler does not export com.sun.tools.javac.parser to unnamed module
What happened?
When trying to run programatically palantir java formatter:
var formatter = com.palantir.javaformat.java.Formatter.create();
formatter.formatSourceAndFixImports(source);
Throw the following exception
java.lang.IllegalAccessError: class com.palantir.javaformat.java.ImportOrderer (in unnamed module @0x544fe44c) 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 @0x544fe44c
at com.palantir.javaformat.java.ImportOrderer.<clinit>(ImportOrderer.java:111)
at com.palantir.javaformat.java.Formatter.formatSourceAndFixImports(Formatter.java:260)
What did you want to happen?
Wouldn't replacing com.sun
imports with org.openjdk
fix this errors?
https://github.com/palantir/palantir-java-format/blob/develop/palantir-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java#L29
(I much rather not have to add those jvm args as this is for a cli tool and it will be a bit inconvenient)
I am running into this as well, with JDK21 being the new LTS and excavator trying to push to it.
class com.palantir.javaformat.java.ImportOrderer (in unnamed module @0x5d2b1399) 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 @0x5d2b1399