Skip to content

RightCurly: false negative in ALONE and anonymous classes #4058

@MEZk

Description

@MEZk
$ cat TestClass.java
public class TestClass {
  void method() {
     new Object() { @Override protected void finalize() { "".toString(); }  int b = 10; };
  }
}

$ 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="RightCurly">
             <property name="option" value="alone"/>
             <property name="tokens" value="METHOD_DEF, INSTANCE_INIT"/>
         </module>
    </module>
</module>

$ java -jar checkstyle-7.6-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:3:74: '}' at column 74 should be alone on a line. [RightCurly]
Audit done.
Checkstyle ends with 1 errors.

74 is a position of } for method finalize
Expected: 2 violations on line 3 (column 74 and 89).
89 is a position of } for anonymous class;

} int b = 10; } this two } should be violated.
Note that shouldStartLine (false, true) does not affect the logic. So the problem is in shouldBeAloneOnLine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions