Skip to content

One input, two outputs: getFormatReplacements does not reflow long strings #33

Description

@abashev

What

Upstream palantir/palantir-java-format#1452 (open since 2025-10-24) reports that IntelliJ and Maven format the same file differently: the IDE wraps a long string, the build leaves it alone, so editing a file in the IDE pollutes the commit and then fails the build's check. The reason is that the two go through different entry points of the library.

We have the same split, in a different place. Checked here on 2.98.0.2 with the reporter's file:

class Test {
    public static void main(String[] args) {
        String example =
                "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah";
    }
}
Path What it calls Wraps the long string
CLI, the GitHub Action, the pre-commit hook Main, reflow on unless --skip-reflowing-long-strings yes
Gradle, the Spotless step formatSourceReflowStringsAndFixImports yes
IntelliJ plugin the native binary or the bootstrapped CLI with --output-replacements yes
Eclipse plugin, and anything else on the SPI FormatterService.getFormatReplacements no

Running both library entry points over that file gives two different files: getFormatReplacements keeps the 119-column line, formatSourceAndFixImports breaks it into a concatenation. Formatter.formatSourceAndFixImports ends with StringWrapper.wrap; Formatter.getFormatReplacements has no such step.

Why it matters here

The manifesto says one style and nothing to tune, which only holds if the same file gives the same bytes wherever it is formatted. Today a file formatted by the Eclipse plugin can fail the check the GitHub Action runs, and neither output is wrong by itself. The Maven plugin in #26 would have to pick a side as well, and whichever it picks, half the users disagree with it.

To decide first

Done when

  • a test formats one file through every entry point — CLI, the Spotless step, the SPI, the native binary — and asserts the results are identical;
  • the Eclipse plugin agrees with the CLI;
  • the SPI javadoc states what each method does to long strings;
  • whatever the Maven plugin (Add a Maven plugin with format and check goals #26) is built on inherits that answer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions