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

Cache: file skipped on 2nd run when exception happened on it in first run #6297

Closed
rnveach opened this Issue Dec 18, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@rnveach
Copy link
Member

rnveach commented Dec 18, 2018

Exceptions are a rare case in checkstyle.

$diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheck.java
index fc59988..4d5b65a 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheck.java
@@ -297,7 +297,7 @@
     private static DetailAST getFirstAnnotationOnSameLine(DetailAST annotation) {
         DetailAST previousAnnotation = annotation;
         final int lastAnnotationLineNumber = previousAnnotation.getLineNo();
-        while (previousAnnotation.getPreviousSibling() != null
+        while (previousAnnotation.getPreviousSibling() == null
                 && previousAnnotation.getPreviousSibling().getLineNo()
                     == lastAnnotationLineNumber) {
             previousAnnotation = previousAnnotation.getPreviousSibling();

$ java -jar checkstyle-master-all.jar -c config\checkstyle_checks.xml src\test\resources\com\puppycrawl\tools\checkstyle\checks\sizes\methodcount\InputMethodCount2.java -Dcheckstyle.header.file="${workspace_loc}\checkstyle\config\java.header" -Dcheckstyle.suppressions.file="${workspace_loc}\checkstyle\config\suppressions.xml" -Dcheckstyle.suppressions-xpath.file="${workspace_loc}\checkstyle\config\suppressions-xpath.xml" -Dcheckstyle.regexp.header.file="${workspace_loc}\checkstyle\config\java_regexp.header" -Dcheckstyle.importcontrol.file="${workspace_loc}\checkstyle\config\import-control.xml" -Dcheckstyle.importcontroltest.file="${workspace_loc}\checkstyle\config\import-control-test.xml" -Dcheckstyle.cache.file="${workspace_loc}\checkstyle\target\cachefilet"
Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing M:\checkstyleWorkspace\checkstyle\src\test\resources\com\puppycrawl\tools\checkstyle\checks\sizes\methodcount\InputMethodCount2.javaCheckstyle ends with 1 errors.

	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:297)
	at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:217)
	at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:390)
	at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:313)
	at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:180)
	at com.puppycrawl.tools.checkstyle.Main.main(Main.java:119)
Caused by: java.lang.NullPointerException
	at com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.getFirstAnnotationOnSameLine(LeftCurlyCheck.java:301)
	at com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.skipAnnotationOnlyLines(LeftCurlyCheck.java:284)
	at com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.visitToken(LeftCurlyCheck.java:182)
	at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:390)
	at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:501)
	at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:330)
	at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:183)
	at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:81)
	at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:319)
	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:289)
	... 5 more

$ cat cachefilet
#Mon Dec 17 19:43:20 EST 2018
M\:\\checkstyleWorkspace\\checkstyle\\src\\test\\resources\\com\\puppycrawl\\tools\\checkstyle\\checks\\sizes\\methodcount\\InputMethodCount2.java=1544361750340
module-resource*?\:M\:\\checkstyleWorkspace\\checkstyle\\config\\suppressions.xml=52C73A2BBFD057C34F37A85D9B94F1F0F64A3380
module-resource*?\:file\:/M\:/checkstyleWorkspace/checkstyle/config/import-control-test.xml=5BAC39384EF046C9FA74A807FEAE02A1D747CB3B
module-resource*?\:file\:/M\:/checkstyleWorkspace/checkstyle/config/java_regexp.header=A70107549356B0396EBC37EA095790DE75CC5193
module-resource*?\:file\:/M\:/checkstyleWorkspace/checkstyle/config/import-control.xml=6D0857449EC5F13E840DAE1AFF27AE173F362562
module-resource*?\:file\:/M\:/checkstyleWorkspace/checkstyle/config/java.header=161CF9951A52797C446FABDE4A493DFE7DE2A819
module-resource*?\:M\:\\checkstyleWorkspace\\checkstyle\\config\\suppressions-xpath.xml=F6BE4270F2DFC3FC154076CCA45D379085FDA4F6
configuration*?=4A64B8FDA513A8C0126E4073E611CC65B0A81CF1

I am expecting the java file to not be added to the cache file. The 2nd time it is run, it sees the file in the cache and skips over it resulting in no exception on the 2nd run. The exception should continue until it is added to BeforeExecutionExclusionFileFilter or the check has been fixed.

@rnveach

This comment has been minimized.

Copy link
Member Author

rnveach commented Feb 18, 2019

FIx was merged

@rnveach rnveach closed this Feb 18, 2019

@rnveach rnveach added this to the 8.18 milestone Feb 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.