Skip to content

[java] Make UseCollectionIsEmpty can detect collection of other class #3685

@Zustin

Description

@Zustin

Affects PMD Version:6.41.0

Rule:UseCollectionIsEmpty

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

Description:
Hi, I found that rule UseCollectionIsEmpty cannot detect list filed from other classes, which is used as list.size()==0. Please refer to the following case:

Code Sample demonstrating the issue:

class Class1 {
    public static List<Integer> list1 = new ArrayList<>();
}
class Class2 {
    public void foo() {
        if(Class1.list1.size() == 0) {}  // should report a warning here, but no warning
    }
}

Expected outcome:

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

Running PMD through: [Maven]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.a:false-negativePMD doesn't flag a problematic piece of codein:symbol-tableAffects the symbol table code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions