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

ModifiedControlVariableCheck crashes for some nested loops with multiple assignments #4630

Closed
denizarsan opened this Issue Jul 6, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@denizarsan

denizarsan commented Jul 6, 2017

$ javac C.java

$ cat C.java

class C {
    void m(int[] a) {
        for (int i = 0, j = 1; ; i++, j++) {
            for (int k : a) {
            }
        }
    }
}

$ cat config.xml

<!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="ModifiedControlVariable">
      <property name="skipEnhancedForLoopVariable" value="true"/>
    </module>
  </module>
</module>

$ java -jar checkstyle-8.0-all.jar -c config.xml C.java

Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing C.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:430)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:362)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:177)
Caused by: java.util.NoSuchElementException
        at java.util.ArrayDeque.removeFirst(ArrayDeque.java:280)
        at java.util.ArrayDeque.pop(ArrayDeque.java:517)
        at com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck.popCurrentVariables(ModifiedControlVariableCheck.java:348)
        at com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck.leaveForDef(ModifiedControlVariableCheck.java:338)
        at com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck.leaveToken(ModifiedControlVariableCheck.java:226)
        at com.puppycrawl.tools.checkstyle.TreeWalker.notifyLeave(TreeWalker.java:384)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:508)
        at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:310)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:182)
        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.

The input class is quite minimized as removing almost any part makes the tool pass.

@rnveach rnveach added the approved label Jul 6, 2017

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jul 6, 2017

Member

Exception has been around since 6.8 when skipEnhancedForLoopVariable was added.

Member

rnveach commented Jul 6, 2017

Exception has been around since 6.8 when skipEnhancedForLoopVariable was added.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Aug 2, 2017

Member

fix is merged

Member

romani commented Aug 2, 2017

fix is merged

@romani romani closed this Aug 2, 2017

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