-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
a:false-positivePMD flags a piece of code that is not problematicPMD flags a piece of code that is not problematic
Milestone
Description
Affects PMD Version: 7.0.0-rc2
Rule: UseArraysAsList
Description:
UseArraysAsList is reported even if the array can't be turned directly into a list due to other actions or conditions in the loop.
Code Sample demonstrating the issue:
public List<String> convertToNonEmptyList(String[] arr) {
List<String> resultList = new ArrayList<>();
for (String item: arr) {
if (item.isEmpty()) {
continue;
}
resultList.add(item);
}
return resultList;
}Expected outcome:
In the above example, empty strings in the initial array wouldn't be present in the resulting list. This isn't equivalent to Arrays.asList(...), so UseArraysAsList shouldn't be reported.
Running PMD through: Maven (using maven-pmd-plugin version 3.20.1-pmd-7-SNAPSHOT configured with PMD 7.0.0-rc2)
jbisotti and Frettman
Metadata
Metadata
Assignees
Labels
a:false-positivePMD flags a piece of code that is not problematicPMD flags a piece of code that is not problematic