A RetroSearch Logo

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

Search Query:

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

[java] UseArraysAsList false negative with for-each loop · Issue #3331 · pmd/pmd · GitHub

Affects PMD Version: 6.36.0-SNAPSHOT

Rule: UseArraysAsList

Description:

The rule doesn't consider for-each loops, only for-loops are recognized.

Code Sample demonstrating the issue:

    <test-code>
        <description>[java] UseArraysAsList false negative with for-each loop</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>8</expected-linenumbers>
        <code><![CDATA[
import java.util.ArrayList;
import java.util.List;

public class UseArraysAsListFN {
    public List<String> convert(String[] arr) {
        List<String> result = new ArrayList<>();
        for (String s : arr) {
            result.add(s);  // violation expected
        }
        return result;
    }
}
        ]]></code>
    </test-code>

Expected outcome:

PMD should report a violation at line 8, but doesn't. This is a false-negative.


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