palantir / palantir/palantir-java-format

`palantir-java-format` cannot parse JEP 512 compact source files / instance `main` on JDK 25 (`expected token: 'void'`)

Open
#1,701 0 comments 1 reaction 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

Summary

palantir-java-format fails to format compact source files (JEP 512, finalized in Java 25): a .java
file whose top-level members (e.g. an instance void main()) are not wrapped in a class declaration.
Formatting such a file fails during parsing with:

InstanceMain.java:1:2: error: expected token: 'void'; generated class instead

The formatter appears to require a top-level type declaration and cannot handle implicitly-declared classes.

Affected versions
  • Reproduced on 2.84.0 and the latest 2.92.0 (2026-06-10).
  • Runtime: JDK 25 (Azul Zulu 25.0.2) — i.e. a JVM that does support JEP 512, so this is a formatter
    parser limitation rather than a JDK-API/runtime issue. (The earlier JDK-25 runtime NoSuchMethodError
    was already fixed in 2.71.0 via #1305 / #1367, so the formatter otherwise runs fine on JDK 25.)
Minimal reproduction

InstanceMain.java — a compact source file (no enclosing class):

void main() {
    System.out.println("Hello from an instance main method");
}

Run the formatter on JDK 25 (the standard jdk.compiler --add-exports / --add-opens flags are required
on JDK 16+, as documented in the README):

java \
  --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
  -cp palantir-java-format-2.92.0.jar:<runtime deps> \
  com.palantir.javaformat.java.Main InstanceMain.java

Result:

InstanceMain.java:1:2: error: expected token: 'void'; generated class instead
Expected behaviour

The file is formatted. Compact source files are valid Java 25 source (javac compiles and java runs them),
so at minimum the formatter should parse top-level members without requiring an explicit enclosing class.

Context / references
  • JEP 512 — Compact Source Files and Instance Main Methods: https://openjdk.org/jeps/512
  • google-java-format added initial instance-main support in v1.34.0
    (google/google-java-format#1216); palantir-java-format periodically merges from google-java-format.
  • Related palantir gaps on new Java syntax (for cross-reference):
    • Module imports (JEP 511): #1506
    • Unnamed patterns (JEP 456, case Foo(_, x)): #1614 / PR #1579

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 by reproducing the failure with com.palantir.javaformat.java.Main on JDK 25 using the InstanceMain.java example and the documented module flags. Trace the parser path used by Main to determine how compact source files are handled; done means the example formats successfully without requiring an enclosing class.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.