palantir / palantir/palantir-java-format

JDK 11 and local field name "sealed" cause error

Open
#865 3 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

What happened?

Test class:

package org.test;

public class Test {
    void test() {
        String sealed = "a sealed test";
    }
}

executing: mvn -V spotless:2.36.0:apply

JDK 11
Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Java version: 11.0.18, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk@11/11.0.18/libexec/openjdk.jdk/Contents/Home

...

[INFO] --- spotless:2.36.0:apply (default-cli) @ test ---
[ERROR] Step 'palantir-java-format' found problem in 'src/main/java/org/test/Test.java':
No enum constant javax.lang.model.element.Modifier.SEALED
java.lang.IllegalArgumentException: No enum constant javax.lang.model.element.Modifier.SEALED
    at java.lang.Enum.valueOf (Enum.java:240)
    at javax.lang.model.element.Modifier.valueOf (Modifier.java:47)
    at com.palantir.javaformat.java.ModifierOrderer.asModifier (ModifierOrderer.java:145)
    at com.palantir.javaformat.java.ModifierOrderer.reorderModifiers (ModifierOrderer.java:59)

JDK 17
Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Java version: 17.0.6, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk@17/17.0.6/libexec/openjdk.jdk/Contents/Home

...

[INFO] --- spotless:2.36.0:apply (default-cli) @ test ---
[INFO] Writing clean file: ..../src/main/java/org/test/Test.java
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

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 report with the supplied Test class under JDK 11, then inspect ModifierOrderer.asModifier and reorderModifiers in the stack trace. Trace how the local identifier "sealed" is interpreted during modifier ordering. Done means spotless:2.36.0:apply completes without the No enum constant error on JDK 11, with regression coverage for this example.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.