Skip to content

Bring over upstream #1784: run the string wrapping pass to a fixed point - #46

Merged
abashev merged 2 commits into
mainfrom
upstream-pr-1784
Sep 23, 2026
Merged

abashev merged 2 commits into
mainfrom
upstream-pr-1784

Conversation

@abashev

@abashev abashev commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Closes #34. Brings over palantir#1784, which fixes palantir#1343.

From upstream, with the author kept

  • Run the string wrapping pass to a fixed point palantir/palantir-java-format#1784 by Zayan Khan, commit authored by them, keeping upstream's Co-authored-by trailer. StringWrapper derives a text block's indentation from the layout around it, and the same pass can move that layout, so one round is not always a fixed point. wrap now repeats the pass while it keeps changing the source, up to MAX_ROUNDS = 5.
    • Paths moved from palantir-java-format/ to open-java-format/; the changelog entry is left out.
    • The upstream golden palantir-issue-1343-text-block-indent-stable comes with it.

Added here

Checked

  • All three goldens fail without the change and pass with it.
  • ./gradlew :open-java-format:test on JDK 21: 1429 tests, all green.
  • JDK 21 sources, 15,747 files: one formats differently, java/lang/Module.java, with a text block argument like the first new golden. The old code moved it again on a second run; the new first run gives exactly the old second run's result and is stable. Formatting the sources takes no longer (30–34 s before, 32–33 s after, within noise).
  • The other 429 JDK files that change on a second run still do; this pass is not what moves them. 304 of them are the blank lines that Stop an unused import from leaving two blank lines behind #43 fixes. The rest change elsewhere, for example string concatenations that the main formatting pass lays out again.

Version

The output changes only for files that were never stable: on a file that is already a fixed point, one round is the same as before. #34 asks to show that on a corpus before it ships; the numbers above are that run.

ZayanKhan-12 and others added 2 commits September 23, 2026 10:53
From palantir#1784 by Zayan Khan, which fixes
palantir#1343 (#34 here). The indentation
StringWrapper picks for a text block is derived from the layout around
it, but the same pass can move that layout, so one round is not always
a fixed point. In the nested array initialisers of
palantir#1343 the second text block moved four
columns on a second run, so a file that --replace had just written was
reported by --set-exit-if-changed. wrap already recomputed its
replacements after reformatting, twice; it now repeats the pass while
it keeps changing the source, up to MAX_ROUNDS = 5.

Adapted while bringing it over: paths moved from palantir-java-format/
to open-java-format/, and the changelog entry left out.

Of the 15,747 files of the JDK 21 sources one formats differently,
java/lang/Module.java, whose text block argument the old code moved
again on a second run; one run now gives that second result. Formatting
the sources takes no longer.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
A text block that is a method argument with more arguments after it,
and a text block in each branch of a ternary, came out of one run at one
indentation and out of the next at another. The inputs come from
google/google-java-format#805 and google/google-java-format#1378, where
they show other symptoms; the first is also the shape of
java/lang/Module.java, the one JDK 21 file the fixed point changes.
With the string wrapping pass run to a fixed point, one run gives the
second result; without it, both new goldens fail (#34).
@abashev
abashev enabled auto-merge September 23, 2026 07:54
@abashev
abashev disabled auto-merge September 23, 2026 08:28
@abashev
abashev merged commit e2142e5 into main Sep 23, 2026
10 checks passed
@abashev
abashev deleted the upstream-pr-1784 branch September 23, 2026 08:28
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.

string block collaps on empty line Bring over upstream PR #1784: run the string wrapping pass to a fixed point

2 participants