Skip to content

Incorrect Indentation errors for expression switches with google_checks.xml #12817

@cushon

Description

@cushon
$ javac -fullversion
javac full version "20-ea+35-2342"
$ javac T.java

$ wget https://raw.githubusercontent.com/checkstyle/checkstyle/d02e867225c3eaa43dc681c2827ce89799dee88f/src/main/resources/google_checks.xml

$ cat T.java
class T {
  void doSomething(int i) {
    String s =
        switch (i) {
          case 1 -> "one";
          case 2 -> "two";
          default -> throw new AssertionError();
        };
  }
}
$ RUN_LOCALE="-Duser.language=en -Duser.country=US"
$ java -jar checkstyle-10.8.1-all.jar -c google_checks.xml T.java
Starting audit...
[WARN] /tmp/tmp.zK57404080/T.java:4:9: 'switch' has incorrect indentation level 8, expected level should be 4. [Indentation]
[WARN] /tmp/tmp.zK57404080/T.java:5:11: 'case' child has incorrect indentation level 10, expected level should be 6. [Indentation]
[WARN] /tmp/tmp.zK57404080/T.java:6:11: 'case' child has incorrect indentation level 10, expected level should be 6. [Indentation]
[WARN] /tmp/tmp.zK57404080/T.java:7:11: 'case' child has incorrect indentation level 10, expected level should be 6. [Indentation]
[WARN] /tmp/tmp.zK57404080/T.java:8:9: 'switch rcurly' has incorrect indentation level 8, expected level should be 4. [Indentation]
Audit done.

Describe what you expect in detail.

I expected no errors to be produced, because the input is formatted in a way that complies with the Google Java Style Guide

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions