Skip to content

Checkstyle requires inconsistent indentation for lambda arguments #13539

@lbenedetto

Description

@lbenedetto
/var/tmp $ javac TestEnum.java
/var/tmp $ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <module name="Indentation"/>
  </module>
</module>
/var/tmp $ cat TestEnum.java
package com.mypackage;

import java.util.function.Consumer;
import java.util.function.Function;

public enum TestEnum {
  NAME(
      String::getClass,
      any -> {}
  );


    TestEnum(
        Function<String, Class<?>> function,
        Consumer<String> consumer
    ) {

    }
}
/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-10.12.2-all.jar -c config.xml TestEnum.java
Starting audit...
[ERROR] /var/tmp/TestEnum.java:9:7: 'lambda arguments' has incorrect indentation level 6, expected level should be 10. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

Describe what you expect in detail.
This should be valid, but is not

  NAME(
      String::getClass,
      any -> {}
  );

This should not be valid, but it is

  NAME(
      String::getClass,
          any -> {}
  );

I believe the issue lies with the lineWrappingIndentation. I tried setting all int properties of Identation to 0 and then one at a time setting them to 100. The one that triggered the error was lineWrappingIndentation, which said 'lambda arguments' has incorrect indentation level 6, expected level should be 106.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions