A RetroSearch Logo

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

Search Query:

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

[java] UnnecessaryLocalBeforeReturn false positive when cloning Maps · Issue #282 · pmd/pmd · GitHub

Rule Set:

    <rule ref="rulesets/java/basic.xml"/>
    <rule ref="rulesets/java/braces.xml"/>
    <rule ref="rulesets/java/codesize.xml"/>

    <rule ref="rulesets/java/coupling.xml">
        <exclude name="LawOfDemeter"/>
        <exclude name="LoosePackageCoupling"/>
    </rule>

    <rule ref="rulesets/java/design.xml">
        <exclude name="UseVarargs"/>
        <exclude name="UseUtilityClass"/>
        <exclude name="SingularField"/>
        <exclude name="CloseResource"/>
    </rule>

    <rule ref="rulesets/java/empty.xml"/>
    <rule ref="rulesets/java/imports.xml"/>

    <rule ref="rulesets/java/naming.xml/LongVariable" />
    <rule ref="rulesets/java/naming.xml/ClassNamingConventions" />
    <rule ref="rulesets/java/naming.xml/MethodWithSameNameAsEnclosingClass" />
    <rule ref="rulesets/java/naming.xml/SuspiciousHashcodeMethodName" />
    <rule ref="rulesets/java/naming.xml/SuspiciousConstantFieldName" />
    <rule ref="rulesets/java/naming.xml/SuspiciousEqualsMethodName" />
    <rule ref="rulesets/java/naming.xml/AvoidFieldNameMatchingTypeName" />
    <rule ref="rulesets/java/naming.xml/PackageCase" />
    <rule ref="rulesets/java/naming.xml/BooleanGetMethodName" />

    <rule ref="rulesets/java/optimizations.xml/UseArrayListInsteadOfVector" />
    <rule ref="rulesets/java/optimizations.xml/UseArraysAsList" />
    <rule ref="rulesets/java/optimizations.xml/AvoidArrayLoops" />
    <rule ref="rulesets/java/optimizations.xml/UnnecessaryWrapperObjectCreation" />

    <rule ref="rulesets/java/typeresolution.xml/LooseCoupling"/>
    <rule ref="rulesets/java/typeresolution.xml/UnusedImports"/>

    <rule ref="rulesets/java/unnecessary.xml"/>

Description:
False positive when making a clone of a hashmap

Code Sample demonstrating the issue:

public class CustomerErrorCollector {

    private final ConcurrentHashMap<String, String> customerErrors = new ConcurrentHashMap<>();

    public void error(String customerNr, String errorMsg) {
        customerErrors.put(customerNr, errorMsg);
    }

    public Map<String, String> getAndReset() {
        final Map<String, String> copy = new HashMap<>(customerErrors);
        customerErrors.clear();
        return copy; // PMD complains that variable could be avoided
    }


}

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