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] UseArraysAsList false positive with non-trivial loops · Issue #3965 · pmd/pmd

[java] UseArraysAsList false positive with non-trivial loops #3965

New issue
Copy link
New issue
Copy link
Closed
#3966
Closed
[java] UseArraysAsList false positive with non-trivial loops#3965
#3966
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.46.0

Description

@adangel
adangel
opened on May 12, 2022
Issue body actions

Affects PMD Version: 6.45.0

Rule: UseArraysAsList

Description: The rule should only report simple, trivial loops, that do nothing more than converting an array into a list.

Code Sample demonstrating the issue:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test {
    public void foo(Integer[] ints) {
        List<Integer> l = new ArrayList<>(100);
        for (int i = 0; i < 100; i++) {
            switch (lookup(ints[i])) {
            case 1: l.add(ints[i]); break; // line 10 - false positive
            case 2: l.addAll(getInts(i)); break;
            }
        }

        List<Integer> anotherList = new ArrayList<>();
        for (int i : ints) {
            switch (lookup(i)) {
            case 1: anotherList.add(i); break; // line 18 - false positive
            case 2: anotherList.addAll(getInts(i)); break;
            }
        }
    }

    int lookup(int a) {
        return a;
    }

    List<Integer> getInts(int a) {
        return Arrays.asList(a);
    }
}

Expected outcome:

PMD reports a violation at lines 10 and 18, but that's wrong. That's a false positive.

Activity

  1. adangel
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on May 12, 2022
  2. adangel
    added a commit that references this issue on May 12, 2022

    [java] UseArraysAsList - ignore non-trivial loops

    This issue will close once commit 28b0d13 is merged into the 'main' branch.
    28b0d13
  3. adangel
    added this to the 6.46.0 milestone on May 12, 2022
  4. adangel
    closed this as completedin 28b0d13on May 26, 2022
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.46.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.