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

google-java-format fails on text blocks with too long lines

Open abrudin opened this issue 5 years ago • 2 comments

If you happen to have a source file with a text block that has individual rows that are too long, like in the following example class:

public class Example {
  private final String test = """
      Something that really definitely is regarded to be too long to fit on one row according to google-java-format
      Something else that really definitely is regarded to be too long to fit on one row according to google-java-format""";
}

, then google-java-format 1.9 outputs:

Example.java:error: Something has gone terribly wrong. Please file a bug: https://github.com/google/google-java-format/issues/new

=== Actual: ===

public class Example {
    private final String test = "Something that really definitely is regarded to be too long to fit on one row\"\n    + \" according to google-java-format\nSomething else that really definitely is\"\n    + \" regarded to be too long to fit on one row according to google-java-format";
}
=== Expected: ===

public class Example {
    private final String test = "Something that really definitely is regarded to be too long to fit on one row according to google-java-format\nSomething else that really definitely is regarded to be too long to fit on one row according to google-java-format";
}

abrudin avatar Oct 09 '20 09:10 abrudin

Any workarounds? Or fix coming? 🤞🏼

nhoughto avatar Jun 16 '21 11:06 nhoughto

@nhoughto A simple workaround seems to be to end the last line with a \ and then close the multiline comment on the next line:

public class Example {
  private final String test = """
      Something that really definitely is regarded to be too long to fit on one row according to google-java-format
      Something else that really definitely is regarded to be too long to fit on one row according to google-java-format\
      """;
}

abrudin avatar Aug 19 '21 16:08 abrudin