Skip to content

ParenPad: thinks precedence parens are a METHOD_CALL instead of an EXPR, new token TokenTypes.DOT should be supported #3048

@WadeWalker

Description

@WadeWalker

Hi guys! Firstly, thank you for all your efforts over the years with Checkstyle -- I've gotten a lot of use out of it, both personally and at work :)

Secondly, I'd like to report what looks like a bug. When upgrading from Checkstyle 5.6 to 6.16.1, I noticed a bunch of new ParenPad warnings. They were triggered by things like this:

E:\Users\Wade\Downloads\Checkstyle bug report>javac Test.java

E:\Users\Wade\Downloads\Checkstyle bug report>cat Test.java
package test;

public class Test {
    static void main( String [] args ) {
        String s = "test";
        Object o = s;
        ((String)o).length();
    }
}
E:\Users\Wade\Downloads\Checkstyle bug report>cat config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker"> <property name="severity" value="warning"/>
        <module name="ParenPad">
            <property name="tokens" value="METHOD_CALL"/>
            <property name="option" value="space"/>
        </module>
    </module>
</module>

E:\Users\Wade\Downloads\Checkstyle bug report>java -jar checkstyle-6.17-all.jar -c config.xml Test.java
Starting audit...
[WARN] E:\Users\Wade\Downloads\Checkstyle bug report\Test.java:7:10: '(' is not followed by whitespace. [ParenPad]
[WARN] E:\Users\Wade\Downloads\Checkstyle bug report\Test.java:7:19: ')' is not preceded with whitespace. [ParenPad]
Audit done.

Here's the additional data you wanted. The expected output is no warnings. The actual output incorrectly shows the parens around "(String)o" to be a METHOD_CALL.

It seems like Checkstyle now thinks the parens around (Wavefront)oElement are a method call instead of just an expression. If I remove METHOD_CALL from the ParenPad configuration, the warning goes away. Or if I put spaces inside like this
( (Wavefront)oElement ).getType()
the warning also goes away. Sorry, but I don't know exactly which version of Checkstyle this change occurred in, since I hadn't upgraded for a while.

Please let me know if you need any additional information, and thanks again!

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