Skip to content

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

Description

@blacksails

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)
    }
}

Activity

  1. nedtwigg commented on Nov 11, 2024

    @nedtwigg
    Member

    This is a bug in GJF, not Spotless. You'll have to report it there.

  2. blacksails commented on Nov 18, 2024

    @blacksails
    Author

    @nedtwigg Why is this a GJF and not a spotless bug? I would always expect spotless to do the same as GJF.

    What GJF does to long strings also complies with the googla java style guide. https://google.github.io/styleguide/javaguide.html#s4.5.2-line-wrapping-indent. So I cant really put up a bug report about it there?

  3. nedtwigg commented on Nov 18, 2024

    @nedtwigg
    Member

    I would always expect spotless to do the same as GJF.

    I would expect that too, and so far I don't have any evidence that it doesn't. Have you tried using GJF with AOSP on this same file?

  4. blacksails commented on Nov 20, 2024

    @blacksails
    Author

    Have you tried using GJF with AOSP on this same file?

    @nedtwigg Sorry if it wasent clear from my issue, but that is exactly what I have done and shown in the snippets in the issue. First snippet is input, next is GJF with AOSP, last is Spotless with GJF and AOSP.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions