Skip to content

False positives for google_checks when using switch expression in lambda #17120

@Edarke

Description

@Edarke

I have read check documentation: https://checkstyle.sourceforge.io/checks/misc/indentation.html#Indentation
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

/var/tmp $ javac Test.java
/var/tmp$ java -jar google-java-format-1.27.0-all-deps.jar --replace Test.java; cat Test.java
import java.util.Optional;

/** Main class. */
public class Test {

  /** Main method. */
  public static String main(Optional<Integer> opt) {
    return opt.map(
            n ->
                switch (n) {
                  case 1 -> "Test";
                  default -> "Default";
                })
        .orElse("");
  }
}

/var/tmp$ java -jar checkstyle-10.24.0-all.jar -c /google_checks.xml Test.java
Starting audit...
Test.java:10:17: 'switch' has incorrect indentation level 16, expected level should be one of the following: 10, 12. [Indentation]
Test.java:11:19: 'case' child has incorrect indentation level 18, expected level should be one of the following: 12, 14. [Indentation]
Test.java:12:19: 'case' child has incorrect indentation level 18, expected level should be one of the following: 12, 14. [Indentation]
Test.java:13:17: 'switch rcurly' has incorrect indentation level 16, expected level should be one of the following: 10, 12. [Indentation]
Audit done.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions