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

RequireThisCheck: NPE when surrounded by braces #3334

Closed
rnveach opened this Issue Jul 1, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@rnveach
Member

rnveach commented Jul 1, 2016

$ cat TestClass.java
public final class TestClass {
    protected void test() throws Exception {
        {
            boolean hasSponsor = false;

            hasSponsor = true;
        }

        {
            boolean hasChanges = false;


            hasChanges = true;
        }
    }
}


$ 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="RequireThisCheck">
<property name="checkFields" value="true" />
<property name="checkMethods" value="false" />
<property name="validateOnlyOverlapping" value="false" />
</module>
    </module>
</module>

$ java -jar checkstyle-7.0-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:281)
    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:196)
    at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:389)
    at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:323)
    at com.puppycrawl.tools.checkstyle.Main.main(Main.java:161)
Caused by: java.lang.NullPointerException
    at com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck.isUserDefinedArrangementOfThis(RequireThisCheck.java:485)
    at com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck.getClassFrameWhereViolationIsFound(RequireThisCheck.java:461)
    at com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck.getFieldWithoutThis(RequireThisCheck.java:308)
    at com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck.processIdent(RequireThisCheck.java:264)
    at com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck.visitToken(RequireThisCheck.java:225)
    at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:362)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:505)
    at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:304)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:179)
    at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)
    at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:301)
    at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:271)
    ... 4 more
Checkstyle ends with 1 errors.

Removing the braces around hasChanges makes the exception go away.

@romani romani added the approved label Jul 1, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Jul 2, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Jul 5, 2016

romani added a commit that referenced this issue Jul 5, 2016

@romani romani added the bug label Jul 5, 2016

@romani romani added this to the 7.1 milestone Jul 5, 2016

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jul 5, 2016

Member

PR was merged, so issue is fixed.

Member

rnveach commented Jul 5, 2016

PR was merged, so issue is fixed.

@rnveach rnveach closed this Jul 5, 2016

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