Skip to content

Indentation: Switch expression doesn't pass with LeftCurlies on newlines #14014

@jungm

Description

@jungm

I have read check documentation: https://checkstyle.sourceforge.io/checks/misc/indentation.html
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

$ javac Test.java
$ cat Test.java
public class Test
{
    public void test()
    {
        String otherValue = switch("test") 
        {  // violation
            case "test" -> "hi";

            default -> null;
        };
    }
}
$ 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>
$ RUN_LOCALE="-Duser.language=en -Duser.country=US"
$ java $RUN_LOCALE -jar checkstyle-10.12.4-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /home/markus/tmp/checkstyle-test/Test.java:6:9: '{' has incorrect indentation level 8, expected level should be 12. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

$ javac Test.java
$ cat Test.java
public class Test
{
    public void test()
    {
        String otherValue = switch("test") 
            {
            case "test" -> "hi";

            default -> null;
        };
    }
}
$ java $RUN_LOCALE -jar checkstyle-10.12.4-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /home/markus/tmp/checkstyle-test/Test.java:6:13: 'switch lcurly' has incorrect indentation level 12, expected level should be 8. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

Describe what you expect in detail.
Checkstyle can be passed, following the suggested outputs of the Indendation check is just an infinite loop.
Note that I intentionally left out the LeftCurly module with option=nl as it's not needed to reproduce this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions