Skip to content

False positive: indentation inside of constructor parameters inside try block #18614

@lrozenblyum

Description

@lrozenblyum

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

Attention: file contains TABs

E:\temp\CheckstyleReport>type config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <property name="tabWidth" value="4"/>

  <module name="TreeWalker">
    <module name="Indentation" />
  </module>
</module>

E:\temp\CheckstyleReport>type Test.java
public class Test {
        private Test client;

        private Test(String string) {
        }

        private void test() {
                try {
                        client = new Test(
                                null // unexpected violation about indentation
                        );
                } catch (Exception e) {
                }
        }
}
E:\temp\CheckstyleReport>set RUN_LOCALE="-Duser.language=en -Duser.country=US"

E:\temp\CheckstyleReport>java %RUN_LOCALE% -jar checkstyle-13.0.0-all.jar -c config.xml Test.java
Starting audit...
[ERROR] E:\temp\CheckstyleReport\Test.java:10:17: 'new' child has incorrect indentation level 16, expected level should be 20. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

Describe what you expect in detail.
The violation shouldn't be reported: the parameter passed to the constructor is already indented correctly.

NOTE: if we remove the try/catch block the violation disappears.
NOTE2: the file is formatted by tabs


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