google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

not idempotent, slow convergence, and bad converged result

Open tgeng opened this issue 1 year ago • 1 comments

Tested release 1.15.0 with the following

public class Foo {

  private static final String foo =
      "\"aaaaaaaaaaaaaaaaaaaaa\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\","
          + "\"aaaaaaaaaaaaaaaaaaaaa\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\","
          + "\"aaaaaaaaaaaaaaaaaaaaa\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\","
          + "\"aaaaaaaaaaaaaaaaaaaaa\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\","
          + "\"aaaaaaaaaaaaaaaaaaaaa\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"aaaaaaaaaaaaaaaaaaaaa\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n";
}

google-java-format would join the last two lines of string and make the last line even longer. Continue invoking google-java-format would keep joining the last part until the whole string is on a single line.

Workaround:

  1. remove the last \n stops this behavior
  2. make the last line shorter than 100 chars stops this behavior

tgeng avatar Nov 29 '22 23:11 tgeng

Non-idempotence is always a bug; thanks for reporting.

kevinb9n avatar Jan 26 '23 00:01 kevinb9n