google-java-format: Reflow long strings does not give same output

Open
#2,338 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Reproduce the discrepancy with ./gradlew spotlessApply using google-java-format 1.24.0 in AOSP mode and the shown Spotless configuration. Compare its output with direct google-java-format output for the long-string example; done means both produce the same indentation and formatting.

Written by the indexing model from the issue text.

Description

bug-unconfirmed

The following input

public class Test {
    private String longString = "asdf asdf asdf asdf asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfa";
}

Becomes

public class Test {
    private String longString =
            "asdf asdf asdf asdf"
                + " asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfa";
}

Using google-java-format AOSP

When using the gradle task ./gradlew spotlessApply this becomes

public class Test {
    private String longString =
            "asdf asdf asdf asdf"
                    + " asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfa";
}

Gradle version: 8.10.2
Spotless version: 6.25.0 and 7.0.0.BETA4 (same result)
Operating system: macOS 15.0.1

Spotless config:

extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
    java {
        googleJavaFormat("1.24.0").aosp().reorderImports(true)
    }
}
Dominant language
Java
Stars
5.7k
Forks
560
Avg merge
1d 13h
Merged PRs (30d)
43

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.

More from diffplug/spotless

All issues in diffplug/spotless

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.