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:
byte[].class
short[].class
int[].class
long[].class
float[].class
double[].class
boolean[].class
char[].class
(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