Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RightCurly false-positives for multi-block continuation #6466

Closed
Vampire opened this issue Feb 23, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@Vampire
Copy link
Contributor

commented Feb 23, 2019

https://checkstyle.org/config_blocks.html#RightCurly
https://checkstyle.org/property_types.html#rcurly same is default mode

/var/tmp $ javac Foo.java

/var/tmp $ 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="RightCurly">
            <property name="tokens" value="CLASS_DEF"/>
            <property name="tokens" value="CTOR_DEF"/>
            <property name="tokens" value="METHOD_DEF"/>
        </module>
    </module>
</module>

/var/tmp $ cat Foo.java
class Foo {
    public Foo() {
        Thread t = new Thread(new Runnable() {
           @Override
           public void run() {
           } // <--
        });
    } // <--

    public void getId() {
    } // <--
} // <--

/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-8.17-all.jar -c config.xml Foo.java
Starting audit...
[ERROR] /var/tmp/Foo.java:6:12: '}' at column 12 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally). [RightCurly]
[ERROR] /var/tmp/Foo.java:8:5: '}' at column 5 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally). [RightCurly]
[ERROR] /var/tmp/Foo.java:11:5: '}' at column 5 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally). [RightCurly]
[ERROR] /var/tmp/Foo.java:12:1: '}' at column 1 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally). [RightCurly]
Audit done.
Checkstyle ends with 4 errors.

Expected:
No violation
Default mode is same https://checkstyle.org/property_types.html#rcurly

From doc:

Same - Works like alone_or_singleline but the brace should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else or try/catch/finally). If no next part of a multi-block statement present, brace must be alone on line. It also allows single-line format of multi-block statements.

@romani

This comment has been minimized.

Copy link
Member

commented Feb 24, 2019

worked the same on 8.16 and 8.15, so it is not a recent regression.

workaround is to use few instances of Check and do not use same for XXXX_DEF tokens, see successful usage https://checkstyle.org/config_blocks.html#RightCurly_Example_of_Usage .

But I agree issue is valid, Check should not depend on list of tokens that much.

@checkstyle checkstyle deleted a comment from Vampire Mar 3, 2019

@checkstyle checkstyle deleted a comment from Vampire Mar 3, 2019

@romani romani added the approved label Mar 3, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 12, 2019

@Vampire

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

The same problem also exists for LITERAL_FOR, LITERAL_WHILE, STATIC_INIT and INSTANCE_INIT.

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 12, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 12, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 12, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 16, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 16, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 18, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 18, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 19, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 19, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 20, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 22, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 22, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 29, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Apr 9, 2019

@romani romani closed this in #6565 Apr 17, 2019

romani added a commit that referenced this issue Apr 17, 2019

@romani romani added the bug label Apr 17, 2019

@romani romani added this to the 8.20 milestone Apr 17, 2019

peterdemaeyer added a commit to peterdemaeyer/checkstyle that referenced this issue Apr 27, 2019

peterdemaeyer added a commit to peterdemaeyer/checkstyle that referenced this issue Apr 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.