google-java-format
google-java-format copied to clipboard
Formatting not idempotent
In a few edge cases, we've found formatting not be idempotent and requiring multiple rounds of formatting before stabilizing. Here's an example:
Input:
package foo;
import java.util.Set;
public class FormatTest {
private static final Set<String> foo = Set.of(
"11111111111111111111111111111111" // foo foo foo foo foo foo foo foo foo foo foo foo foo foo
);
}
After one round of formatting:
package foo;
import java.util.Set;
public class FormatTest {
private static final Set<String> foo =
Set.of(
"11111111111111111111111111111111" // foo foo foo foo foo foo foo foo foo foo foo foo foo
// foo
);
}
After two rounds of formatting:
package foo;
import java.util.Set;
public class FormatTest {
private static final Set<String> foo =
Set.of(
"11111111111111111111111111111111" // foo foo foo foo foo foo foo foo foo foo foo foo foo
// foo
);
}
At this stage the formatting has stabilized and further rounds will not create any changes.
This is with google-java-format 1.7 and 1.10.0. The same can be reproduced with the Coveo Maven plugin 2.9. I have not tested with other integrations.
Thanks for finding this. We would agree that any non-idempotence is a bug. Since it at least reaches a fixed point quickly (it's like "idempotence, once removed") it might not be high-priority fix, but we're glad to keep this open until then.
https://github.com/google/google-java-format/issues/211