A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/4500 below:

[java] AvoidReassigningLoopVariables - false negatives within for-loops and skip allowed · Issue #4500 · pmd/pmd · GitHub

Affects PMD Version: 7.0.0-rc1

Rule: AvoidReassigningLoopVariables

Description:

This rule might not report anymore all reassignments of the control variable in for-loops when the property forReassign is set to skip.

Code Sample demonstrating the issue:

public class Foo {
    void foo(int bar) {
        for (int i=0; i < 10; i++) {
            doSomethingWith(i);
            if (foo()) {
                i++;
                i--;
                ++i;
                --i;
                i += 1;
                i -= 1;
                doSomethingWith(i++);
                i += 2;    // not OK (line 13)
                i -= 2;    // not OK (line 14)
                i &= 1;    // not OK (line 15)
                i |= 1;    // not OK (line 16)
                i *= 1;    // not OK - is not reported anymore (line 17)
                i /= 1;    // not OK - is not reported anymore (line 18)
                i = i + 1; // not OK - is reported with 7.0.0-rc1 (line 19)
                i = i - 1; // not OK - is reported with 7.0.0-rc1 (line 20)
                i = 5;     // not OK - is reported with 7.0.0-rc1 (line 21)
                doSomethingWith(i = 5); // not OK - is reported with 7.0.0-rc1 (line 22)
            }
        }
    }
}

Expected outcome:

PMD should report violations at lines 13 to 22, but only lines 19 to 22 are reported.

More context:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4