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

MethodCountCheck: add ANNOTATION_DEF to toknes to avoid NPE #4534

Closed
rnveach opened this Issue Jun 27, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@rnveach
Member

rnveach commented Jun 27, 2017

Found at #4532 (comment) .

I surprised that this code is compilable, I thought only methods signatures could be in annotation declaration.

from https://docs.oracle.com/javase/tutorial/java/annotations/declaring.html

Annotation types are a form of interface

$ javac TextClass.java

$ cat TestClass.java
@interface TestClass {
    Object object = new Object(){
        @Override
        public String toString() {
            return new String();
        }
    };
}

$ 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="MethodCount">
        <property name="maxTotal" value="35"/>
      </module>
    </module>
</module>

$ java -jar checkstyle-7.8.2-all.jar -c TestConfig.xml TestClass.java
Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing TestClass.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.sizes.MethodCountCheck$MethodCounter.access$000(MethodCountCheck.java:218)
    at com.puppycrawl.tools.checkstyle.checks.sizes.MethodCountCheck.raiseCounter(MethodCountCheck.java:140)
    at com.puppycrawl.tools.checkstyle.checks.sizes.MethodCountCheck.visitToken(MethodCountCheck.java:112)
    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.
@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jun 27, 2017

Member

Fix was merged

Member

rnveach commented Jun 27, 2017

Fix was merged

@rnveach rnveach closed this Jun 27, 2017

@rnveach rnveach added the bug label Jun 27, 2017

@rnveach rnveach added this to the 8.0 milestone Jun 27, 2017

@rnveach rnveach changed the title from NPE in MethodCountCheck to MethodCountCheck: NPE from lack of annotation class support Jun 27, 2017

@romani romani changed the title from MethodCountCheck: NPE from lack of annotation class support to MethodCountCheck: add ANNOTATION_DEF to toknes to avoid NPE Jul 2, 2017

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