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

[java] AvoidArrayLoops should consider final variables #3847

Closed
ghost opened this issue Mar 16, 2022 · 1 comment · Fixed by #4159
Closed

[java] AvoidArrayLoops should consider final variables #3847

ghost opened this issue Mar 16, 2022 · 1 comment · Fixed by #4159
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@ghost
Copy link

ghost commented Mar 16, 2022

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]

@ghost ghost added the a:false-negative PMD doesn't flag a problematic piece of code label Mar 16, 2022
@ghost

This comment was marked as off-topic.

@adangel adangel changed the title AvoidArrayLoops should detect variable type [java] AvoidArrayLoops should detect variable type Oct 14, 2022
@adangel adangel changed the title [java] AvoidArrayLoops should detect variable type [java] AvoidArrayLoops should consider final variables Oct 14, 2022
adangel added a commit to adangel/pmd that referenced this issue Oct 14, 2022
@adangel adangel added this to the 6.51.0 milestone Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant