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

ConfusingConditionCheck: NPE from CS #454

Closed
rnveach opened this issue May 14, 2016 · 6 comments
Closed

ConfusingConditionCheck: NPE from CS #454

rnveach opened this issue May 14, 2016 · 6 comments
Milestone

Comments

@rnveach
Copy link
Contributor

@rnveach rnveach commented May 14, 2016

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (sevntu-checkstyle-check) on project checkstyle: Failed during checkstyle configuration: Exception was thrown while processing M:\checkstyleWorkspace\checkstyle\src\it\resources\com\google\checkstyle\test\chapter4formatting\rule411bracesareused\InputNeedBraces.java: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (sevntu-checkstyle-check) on project checkstyle: Failed during checkstyle configuration
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:189)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:185)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed during checkstyle configuration
    at org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.execute(CheckstyleViolationCheckMojo.java:543)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 11 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing M:\checkstyleWorkspace\checkstyle\src\it\resources\com\google\checkstyle\test\chapter4formatting\rule411bracesareused\InputNeedBraces.java
    at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:250)
    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:190)
    at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:252)
    at org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.execute(CheckstyleViolationCheckMojo.java:538)
    ... 13 more
Caused by: java.lang.NullPointerException
    at com.github.sevntu.checkstyle.checks.coding.ConfusingConditionCheck.getAmounOfCodeRowsInBlock(ConfusingConditionCheck.java:260)
    at com.github.sevntu.checkstyle.checks.coding.ConfusingConditionCheck.isRatioBetweenIfAndElseBlockSuitable(ConfusingConditionCheck.java:236)
    at com.github.sevntu.checkstyle.checks.coding.ConfusingConditionCheck.visitToken(ConfusingConditionCheck.java:165)
    at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:363)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:478)
    at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:305)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:181)
    at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)
    at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:270)
    at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:240)
    ... 16 more

@romani
Copy link
Member

@romani romani commented May 14, 2016

this Checks is still active in checkstyle_sevntu_checks.xml .
@rnveach , did you do workaround in checkstyle code to avoid NPE ?
please place in this issue code to reproduce problem.

@rnveach
Copy link
Contributor Author

@rnveach rnveach commented May 14, 2016

@romani NPE is from resource file, CS isn't suppose to run against resources. I accidentally stumbled upon this when fixing Sevntu CS run in CS.

I will try to find the exact line.
https://github.com/checkstyle/checkstyle/blob/ccdc3c09c500ccd31d56e4d6ed9c2d86edf2e9f1/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule411bracesareused/InputNeedBraces.java

@romani
Copy link
Member

@romani romani commented May 14, 2016

all resources are compilable , so no NPE is expected for sure.

@rnveach
Copy link
Contributor Author

@rnveach rnveach commented May 15, 2016

@romani here is the trimmed report.

$ cat TestClass.java
package test;

class InputNeedBraces
{
    class InnerEmptyBlocks {
        void foo() {
        }
    }

    InnerEmptyBlocks anon = new InnerEmptyBlocks() {
        boolean flag = true;

        void foo() {
            if(flag); //warn
            else; //warn
        }
    };
}


$ 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="com.github.sevntu.checkstyle.checks.coding.ConfusingConditionCheck" />
    </module>
</module>

$ java -jar checkstyle-sevntu-nightly-2016-05-14-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:249)
    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:190)
    at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:341)
    at com.puppycrawl.tools.checkstyle.Main.main(Main.java:170)
Caused by: java.lang.NullPointerException
    at com.github.sevntu.checkstyle.checks.coding.ConfusingConditionCheck.getAmounOfCodeRowsInBlock(ConfusingConditionCheck.java:256)
    at com.github.sevntu.checkstyle.checks.coding.ConfusingConditionCheck.isRatioBetweenIfAndElseBlockSuitable(ConfusingConditionCheck.java:232)
    at com.github.sevntu.checkstyle.checks.coding.ConfusingConditionCheck.visitToken(ConfusingConditionCheck.java:161)
    at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:363)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:478)
    at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:305)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:181)
    at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)
    at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:270)
    at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:240)
    ... 3 more
Checkstyle ends with 1 errors.

The cause of the exception is the if/else. The if by itself won't cause the exception.

@romani
Copy link
Member

@romani romani commented May 15, 2016

@rnveach , thanks alot, code is amazing :) .

rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Dec 3, 2016
rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Dec 5, 2016
rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Dec 6, 2016
romani added a commit that referenced this issue Dec 6, 2016
@romani romani added this to the 1.23 milestone Dec 6, 2016
@romani
Copy link
Member

@romani romani commented Dec 6, 2016

fix is merged.

@romani romani closed this Dec 6, 2016
kariem added a commit to kariem/sevntu.checkstyle that referenced this issue Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants