Skip to content

[java] LooseCoupling FP with class literal #3940

@dgroup

Description

@dgroup

Affects PMD Version: 6.44.0

Rule: LooseCouplingRule

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#loosecoupling

Description:

Code Sample demonstrating the issue:

public class TheClass {

    private ObjectMapper objectMapper = new ObjectMapper();

    public BiMap<String, Integer> getCountriesDictionary() throws IOException {
        final Map<String, Integer> out = objectMapper.readValue(".....", HashMap.class);
        return HashBiMap.create(out);
    }
}

Expected outcome:

PMD reports a violation at line objectMapper.readValue(".....", HashMap.class);, but that's wrong. That's a false positive.

Running PMD through: Gradle

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions