palantir / palantir/palantir-java-format

jdk.compiler does not export com.sun.tools.javac.parser to unnamed module

Open
#950 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
907
Forks
101
Avg merge
1d 3h
Merged PRs (30d)
19

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in palantir-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java, especially the imports near line 29 and the failing static initialization at line 111. Reproduce the programmatic Formatter.formatSourceAndFixImports call and investigate the jdk.compiler module-access failure; done means the formatter runs without requiring JVM export arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.