A RetroSearch Logo

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

Search Query:

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

[java] UseArraysAsList must ignore primitive arrays · Issue #3379 · pmd/pmd · GitHub

Affects PMD Version:
6.36.0

Rule:
UseArraysAsList

Description:
Arrays of primitive data types must not trigger this rule.
This is especially problematic since replacing the code as suggested would introduce a bug, i.e. an Array with a single entry instead of an Array of values converted from primitive type to Object type (e.g. short into Short).

The following arrays should not trigger the rule:

(I hope I didn't miss any.)

Code Sample demonstrating the issue:

short[] array = (short[]) value;
ArrayList<Short> arrayList = new ArrayList<>(array.length);
for(short v:array) {
    arrayList.add(v);
}

// can't use this:
var list2 = Arrays.asList(array); // type of list2: List<short[]> and not List<Short>

Expected outcome:

PMD reports a violation at line arrayList.add(v); but that's wrong. That's a false positive.

Running PMD through: Gradle


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