Skip to content

[java] AvoidArrayLoops should consider final variables #3847

@ghost

Description

Affects PMD Version:6.42.0

Rule:AvoidArrayLoops

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_performance.html#avoidarrayloops

Description:

Hi, I found a false negative about the rule AvoidArrayLoops. Please read the following case. PMD should have reported a warning at line 6, but it doesn't. However, it can detect line 7. I think line 6 and line 7 are same. Hence, this is a false negative. Thanks for your consideration.

Code Sample demonstrating the issue:

public void sample() {
    int[] a = new int[10];
    int[] b = new int[10];
    final int c = 6;
    for (int i=0;i<10;i++) {
        b[i]=a[i+c];  // should report a warning at this line
        // b[i]=a[i+6];  // This line can be detected
    }
}

Expected outcome: A warning

PMD should report a violation at line 6, but doesn't. This is a false-negative.

Running PMD through: [Maven]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions