A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3867 below:

[java] UseArraysAsList with method call · Issue #3867 · pmd/pmd · GitHub

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4