Skip to content

Indentation check fails for Line Wrapped Anonymous Inner Class with LCurly on newline #3612

@JLLeitschuh

Description

@JLLeitschuh
$ cat TestClass.java
public class TestClass
{
    public static class SimpleClass {
        public void method() {}
    }

    void method()
    {
        final SimpleClass test =
                new SimpleClass() { //indent:16
                    public void method() {}
                }; //indent:16
        final SimpleClass test2 =
                new SimpleClass() //indent:16
                { //indent:16 violation
                    public void method() {}
                }; //indent:16
    }
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<module name="Indentation">
  <property name="tabWidth" value="4" />
  <property name="basicOffset" value="4" />
  <property name="braceAdjustment" value="0" />
  <property name="caseIndent" value="4" />
  <property name="lineWrappingIndentation" value="8" />
  <property name="throwsIndent" value="4" />
  <property name="arrayInitIndent" value="4" />
</module>
    </module>
</module>

$ java -jar checkstyle-7.4-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:15: 'object def lcurly' have incorrect indentation level 16, expected level should be one of the following: 8, 12. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

There are two test cases here, the first, test passes because the LCURLY is on the same line.
test2 fails because the LCURLY is on its own line alone.

the current validation code wants this:

        final SimpleClass test2 =
                new SimpleClass() //indent:16
            { //indent:12
                public void method() {}
            }; //indent:12

https://github.com/JLLeitschuh/checkstyle/commit/661ad249fdb723b12e4c95cbfdf8f758c7465faa#diff-41124079fe0fabb5d72bbb58a1f17c8c
Above has test case and fix.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions