Skip to content

Fails to format an enum declaration with no enums defined #281

@orischwartz

Description

@orischwartz

This java code causes the formatter to throw an exception:

public enum Empty {;}

Minimal testcase:

  @Test
  public void formatsEmptyEnums() throws FormatterException {
    String input = "public enum Empty{;}";
    List<String> expectedLines = asList("public enum Empty {", "  ;", "}", "");

    assertEquals(Joiner.on("\n").join(expectedLines), new Formatter().formatSource(input));
  }

Fails with the following stacktrace:

com.google.googlejavaformat.java.FormatterException: 1:2: error: expected token: ';'; generated } instead
	at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:260)
	at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:234)
	at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:202)

Tested against 1.6-SNAPSHOT at 579772a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions