Skip to content

Indentation: Lambda in Enum causes error loop #11103

@pavelicii

Description

@pavelicii

Check documentation: https://checkstyle.org/config_misc.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 SomeEnum.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 SomeEnum.java
package some.pckg;

import java.util.function.Function;

public enum SomeEnum {

    ENUM_VALUE(
            v -> v, // violation, but it is not expected
            new Object()
    );

    private final Function<Object, Object> function;
    private final Object object;

    SomeEnum(Function<Object, Object> function, Object object) {
        this.function = function;
        this.object = object;
    }
}


/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-9.2-all.jar -c config.xml SomeEnum.java
Starting audit...
[ERROR] C:\test\src\main\java\some\pckg\SomeEnum.java:8:13: 
    'lambda arguments' has incorrect indentation level 12, expected level should be 16. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

I expect Checkstyle to pass without errors. If I try to increase indentation like [ERROR] suggests (from 12 to 16), I get the same error, but with indentation levels 16 and 20 (and so on). So the error is looped. Similar thing happened in #1141.

UPDATE: expected is indention on 8, as lineWrap is 4 and by default Checks demand strict indenation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions