Menu

#1260 Data Flow Analysis misses definitions and references to loop variable

New Tickets
open
nobody
DFA (8)
PMD
3-Major
Bug
5.1.3
2016-12-18
2014-09-11
No

While testing a custom DFA-based rule, I noticed that the DFA engine sometimes misses definitions and references.

To reproduce, just use the rule designer UI and consider the Data Flow Analysis for the following piece of Java code:

public class Test {
   public void method() {

     for (int i = 0; i < 10; i++) {
       System.out.println(i);
     }

     for (int i = 0; i < 10; i++) {
       System.err.println(i);
     }
   }
}

You will notice that the second loop, which has its own version of variable i, shows neither definitions nor references of i. This is certainly a bug, which affects every rule based on DFA.

If one changes i to j in the second loop, DFA behaves more or less as expected, although I wouldn't consider i being defined twice by the first loop either.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2016-12-18
    • Ruleset / Rule: --> DFA
     
  • Andreas Dangel

    Andreas Dangel - 2016-12-18
    • labels: --> DFA
    • Ruleset / Rule: DFA -->
     

Log in to post a comment.