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 with method call · Issue #3867 · pmd/pmd

[java] UseArraysAsList with method call #3867

New issue
Copy link
New issue
Copy link
Closed
#3900
Closed
[java] UseArraysAsList with method call#3867
#3900
Copy link
Assignees
adangel
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.45.0

Description

@adangel
adangel
opened on Mar 22, 2022
Issue body actions

Affects PMD Version: 6.43.0

Rule: UseArraysAsList

Description:

When calling a method on the array element and adding the result, the rule should not be triggered.
The example code on https://pmd.github.io/latest/pmd_rules_java_performance.html#usearraysaslist explictly gives this example case, but still the rule is triggered.

Code Sample demonstrating the issue:

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

public class Test {
    public void foo(Integer[] ints) {
        // could just use Arrays.asList(ints)
        List<Integer> l= new ArrayList<>(100);
        for (int i=0; i< 100; i++) {
            l.add(ints[i]);
        }
        List<Integer> anotherList = new ArrayList<>();
        for (int i=0; i< 100; i++) {
            anotherList.add(ints[i].toString()); // line 13 - false positive 
        }
    }
}

Expected outcome:

PMD reports a violation at line 13, 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 Mar 22, 2022
  2. adangel
    self-assigned this
    on Apr 8, 2022
  3. adangel
    added a commit that references this issue on Apr 8, 2022

    [java] Fix UseArraysAsList with method calls

    This issue will close once commit ddb0ecf is merged into the 'main' branch.
    ddb0ecf
  4. adangel
    added this to the 6.45.0 milestone on Apr 8, 2022
  5. adangel
    closed this as completedin ddb0ecfon Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @adangel
    adangel

Labels

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

Type

No type

Projects

No projects

    Milestone

    • 6.45.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.