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

EmptyBlock: NPE on annotation declaration #4472

Closed
lgoldstein opened this Issue Jun 20, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@lgoldstein

lgoldstein commented Jun 20, 2017

/var/tmp $ javac YOUR_FILE.java
... no errors ...
/var/tmp $ cat YOUR_FILE.java

package com.cb4.common.annotations;                                                                                                                                                                                
                                                                                                                                                                                                                   
import java.lang.annotation.Documented;                                                                                                                                                                            
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
@Documented
public @interface Identity {
    String name() default "";
}

/var/tmp $ cat config.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">
    <module name="TreeWalker">
        <module name="EmptyBlock">
            <property name="tokens" value="LITERAL_WHILE, LITERAL_FINALLY, LITERAL_DO, LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, INSTANCE_INIT, STATIC_INIT, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_CASE, LITERAL_DEFAULT, ARRAY_INIT"/>
        </module>
    </module>
</module>

/var/tmp $ java -jar checkstyle-7.8.2-all.jar -c config.xml YOUR_FILE.java

Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing com/cb4/common/annotations/Identity.java
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:295)
        at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:213)
        at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:425)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:359)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:174)
Caused by: java.lang.NullPointerException
        at com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck.findLeftCurly(EmptyBlockCheck.java:246)
        at com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck.visitToken(EmptyBlockCheck.java:142)
        at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:370)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:507)
        at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:312)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:184)
        at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)
        at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:316)
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:286)
        ... 4 more
Checkstyle ends with 1 errors.

I upgraded from 7.6 to 7.8.2 and simply ran checkstyle via Maven plugin version 2.17. Note: version 7.6 succeeds without a problem.
I have tested this with 7.7 and it happens there as well - 7.6.1 passed

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jun 20, 2017

Member

I can confirm the issue in 7.8.2 .
It happens only with this in the configuration:

        <module name="EmptyBlock">
            <property name="tokens" value="LITERAL_WHILE, LITERAL_FINALLY, LITERAL_DO, LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, INSTANCE_INIT, STATIC_INIT, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_CASE, LITERAL_DEFAULT, ARRAY_INIT"/>
        </module>

The problerm is this line,

&& ast.getNextSibling().getFirstChild().getType() == TokenTypes.SLIST) {
.

Member

rnveach commented Jun 20, 2017

I can confirm the issue in 7.8.2 .
It happens only with this in the configuration:

        <module name="EmptyBlock">
            <property name="tokens" value="LITERAL_WHILE, LITERAL_FINALLY, LITERAL_DO, LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, INSTANCE_INIT, STATIC_INIT, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_CASE, LITERAL_DEFAULT, ARRAY_INIT"/>
        </module>

The problerm is this line,

&& ast.getNextSibling().getFirstChild().getType() == TokenTypes.SLIST) {
.

@rnveach rnveach added the approved label Jun 20, 2017

@checkstyle checkstyle deleted a comment from lgoldstein Jun 21, 2017

@romani romani changed the title from NPE in checkstyle: Failed during checkstyle configuration: Exception was thrown while processing NullPointerException to EmptyBlock: NPE on annotation declaration Jun 21, 2017

soon added a commit to soon/checkstyle that referenced this issue Jul 3, 2017

soon added a commit to soon/checkstyle that referenced this issue Jul 3, 2017

rnveach added a commit that referenced this issue Jul 4, 2017

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jul 4, 2017

Member

Fix is merged

Member

rnveach commented Jul 4, 2017

Fix is merged

@rnveach rnveach closed this Jul 4, 2017

@rnveach rnveach added the bug label Jul 4, 2017

@rnveach rnveach added this to the 8.1 milestone Jul 4, 2017

@rnveach rnveach marked this as a duplicate of #4631 Jul 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment