Skip to content

False-positive RightCurly in google_checks since 8.20 #6807

@alexbde

Description

@alexbde

https://checkstyle.org/config_blocks.html#RightCurly
https://checkstyle.org/property_types.html#rcurly

/var/tmp $ javac RightCurly.java

/var/tmp $ cat RightCurly.java
public class RightCurly {
  public RightCurly() {}
}

/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-8.21-all.jar -c /google_checks.xml RightCurly.java
Starting audit...
[WARN] /var/tmp/RightCurly.java:2:24: '}' at column 24 should be alone on a line. [RightCurlyAlone]
Audit done.

I expected no warning because of section 4.1.3 Empty blocks: may be concise in Google Java Style Guide.

An empty block or block-like construct may be in K & R style (as described in Section 4.1.2). Alternatively, it may be closed immediately after it is opened, with no characters or line break in between ({}), unless it is part of a multi-block statement (one that directly contains multiple blocks: if/else or try/catch/finally).


Problem exists since Checkstyle 8.20, with Checkstyle 8.19 there is no such warning.

Checkstyle 8.20


$ java -Duser.language=en -Duser.country=US -jar checkstyle-8.20-all.jar -c /google_checks.xml RightCurly.java
Starting audit...
[WARN] /var/tmp/RightCurly.java:2:24: '}' at column 24 should be alone on a line. [RightCurlyAlone]
Audit done.

Checkstyle 8.19


$ java -Duser.language=en -Duser.country=US -jar checkstyle-8.19-all.jar -c /google_checks.xml RightCurly.java
Starting audit...
Audit done.

Google config:

<module name="RightCurly">
<property name="id" value="RightCurlyAlone"/>
<property name="option" value="alone"/>
<property name="tokens"
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF"/>
</module>

        <module name="RightCurly">
            <property name="id" value="RightCurlyAlone"/>
            <property name="option" value="alone"/>
            <property name="tokens"
             value="CLASS_DEF, METHOD_DEF, CTOR_DEF, 
                        LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
                    INSTANCE_INIT"/>
</module>

https://checkstyle.org/config_blocks.html#RightCurly
https://checkstyle.org/property_types.html#rcurly


Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedbughas bountyissue has some money incentive to fix it, https://www.bountysource.com/teams/checkstyle/issueshigh demand

    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