GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] AvoidArrayLoops regression: from false negative to false positive with final variables · Issue #4183 · pmd/pmd

[java] AvoidArrayLoops regression: from false negative to false positive with final variables #4183

New issue
Copy link
New issue
Copy link
Closed
#4190
Closed
[java] AvoidArrayLoops regression: from false negative to false positive with final variables#4183
#4190
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.52.0

Description

@Androbin
Androbin
opened on Oct 30, 2022
Issue body actions

Affects PMD Version: 6.51.0

Rule: AvoidArrayLoops

Description:
While fixing #3847, a regression was introduced in #4159 @adangel, now instead of a false negative we have a false positive.
A final variable may only be ignored if it's computed before the loop (or otherwise constant over the loop).

Code Sample demonstrating the issue:

public class Test {
  public static void sample() {
    final int[] a = new int[10];
    final int[] b = new int[10];
    for (int i=0; i<10; i++) {
      final int c = i;
      b[i] = a[i+c];
    }
  }
}

Expected outcome:

PMD reports a violation at line 5, but that's wrong. That's a false positive.

Running PMD through: CLI

True positive code samples
public class Test {
  public static void sample() {
    final int[] a = new int[10];
    final int[] b = new int[10];
    final int c = 6;
    for (int i=0; i<10; i++) {
      b[i] = a[i+c];
    }
  }
}
public class Test {
  public static void sample() {
    final int[] a = new int[10];
    final int[] b = new int[10];
    for (int i=0; i<10; i++) {
      final int c = 6;
      b[i] = a[i+c];
    }
  }
}
True negative code samples
public class Test {
  public static void sample() {
    final int[] a = new int[10];
    final int[] b = new int[10];
    for (int i=0; i<10; i++) {
      int c = i;
      b[i] = a[i+c];
    }
  }
}

Activity

  1. Androbin
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Oct 30, 2022
  2. Androbin
    changed the title [-]AvoidArrayLoops Regression[/-] [+]AvoidArrayLoops Regression: From false negative to false positive with final variables[/+] on Oct 30, 2022
  3. adangel
    changed the title [-]AvoidArrayLoops Regression: From false negative to false positive with final variables[/-] [+][java] AvoidArrayLoops Regression: From false negative to false positive with final variables[/+] on Nov 3, 2022
  4. adangel
    changed the title [-][java] AvoidArrayLoops Regression: From false negative to false positive with final variables[/-] [+][java] AvoidArrayLoops regression: From false negative to false positive with final variables[/+] on Nov 3, 2022
  5. adangel
    changed the title [-][java] AvoidArrayLoops regression: From false negative to false positive with final variables[/-] [+][java] AvoidArrayLoops regression: from false negative to false positive with final variables[/+] on Nov 3, 2022
  6. adangel
    added a commit that references this issue on Nov 3, 2022

    [java] Fix pmd#4183 AvoidArrayLoops false positive

    This issue will close once commit f061ab5 is merged into the 'main' branch.
    f061ab5
  7. adangel
    added this to the 6.52.0 milestone on Nov 3, 2022
  8. adangel
    closed this as completedin f061ab5on Nov 25, 2022
  9. adangel
    added a commit that references this issue on Nov 25, 2022

    Merge pull request pmd#4190 from adangel:issue-4183-AvoidArrayLoops

    This issue will close once commit 366bb3c is merged into the 'main' branch.
    366bb3c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.52.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.