GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [java] UseArraysAsList false positive with non-trivial loops · Issue #3965 · pmd/pmd Closed Labels a:false-positivePMD flags a piece of code that is not problematic Milestone DescriptionAffects PMD Version: 6.45.0 Rule: UseArraysAsList Description: The rule should only report simple, trivial loops, that do nothing more than converting an array into a list. Code Sample demonstrating the issue: import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Test { public void foo(Integer[] ints) { List<Integer> l = new ArrayList<>(100); for (int i = 0; i < 100; i++) { switch (lookup(ints[i])) { case 1: l.add(ints[i]); break; // line 10 - false positive case 2: l.addAll(getInts(i)); break; } } List<Integer> anotherList = new ArrayList<>(); for (int i : ints) { switch (lookup(i)) { case 1: anotherList.add(i); break; // line 18 - false positive case 2: anotherList.addAll(getInts(i)); break; } } } int lookup(int a) { return a; } List<Integer> getInts(int a) { return Arrays.asList(a); } } Expected outcome: PMD reports a violation at lines 10 and 18, but that's wrong. That's a false positive. Activity
MetadataMetadataAssigneesLabelsa:false-positivePMD flags a piece of code that is not problematic TypeProjectsMilestoneRelationshipsDevelopmentIssue 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. |