Skip to content

Formatting not idempotent #614

Closed
Closed

Description

@protocol7

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.

Activity

  1. kevinb9n commented on Jun 14, 2021

    @kevinb9n
    Contributor

    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.

  2. cushon commented on Dec 11, 2023

    @cushon
    Collaborator
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions