Skip to content

Reorder non-sealed as one modifier - #67

Merged
abashev merged 1 commit into
mainfrom
non-sealed-modifier-order
Sep 25, 2026
Merged

abashev merged 1 commit into
mainfrom
non-sealed-modifier-order

Conversation

@abashev

@abashev abashev commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Brings over google/google-java-format#1107, a fix from google-java-format 1.23.

The bug

non-sealed private interface B extends I {} made the whole file fail with error: <identifier> expected. javac lexes non-sealed as three tokens, non, - and sealed, and ModifierOrderer looked at one token at a time: it never saw non-sealed, took the trailing sealed as the modifier to move in front of private, and left non- behind, so the reordered text no longer parsed.

From upstream, with the author kept

  • Fix modifier order handling for non-sealed google/google-java-format#1107 by Liam Miller-Cushon, commit authored by them. The sorter reads the three tokens as one modifier (ModifierTokens) and writes it back whole. Adapted to this codebase's javax.annotation.Nullable and NullAway suppressions. The upstream golden Sealed and the sealedClass unit test come with it, with the expected output in this project's style.

Added here

  • A second ModifierOrdererTest case for the exact shape that failed, non-sealed private.

Checked

  • The golden and the new unit test fail on main and pass with the change.
  • ./gradlew :open-java-format:test on JDK 21: 1503 tests, all green.
  • The 15,747 files of the JDK 21 sources format exactly as before; none of them writes non-sealed out of JLS order.

"non-sealed private interface B" came out as text that no longer
parsed, so the whole file failed with "<identifier> expected". javac
lexes non-sealed as three tokens, "non", "-" and "sealed", and the
modifier sorting looked at one token at a time: it never saw
"non-sealed", took the trailing "sealed" as the modifier to move in
front of "private", and left "non-" behind.

This ports google/google-java-format#1107 by Liam Miller-Cushon: the
sorter now reads the three tokens as one modifier and writes it back
whole. The golden Sealed and the sealedClass test come from upstream,
with the expected output in this project's style; a second unit test
pins the shape that failed.

The 15,747 files of the JDK 21 sources format exactly as before; none
of them writes non-sealed out of order.
@abashev
abashev merged commit 2c63af6 into main Sep 25, 2026
15 checks passed
@abashev
abashev deleted the non-sealed-modifier-order branch September 25, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants