Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
blacksails opened this issue Nov 11, 2024 · 4 comments
Open

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

blacksails opened this issue Nov 11, 2024 · 4 comments

Comments

@blacksails
Copy link

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)
    }
}
@nedtwigg
Copy link
Member

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

@nedtwigg nedtwigg closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2024
@blacksails
Copy link
Author

blacksails commented Nov 18, 2024

@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?

@nedtwigg
Copy link
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?

@blacksails
Copy link
Author

blacksails commented Nov 20, 2024

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
Projects
None yet
Development

No branches or pull requests

2 participants