[java] UseCollectionIsEmpty should infer local variable type from method invocation #3858
Labels
a:false-negative
PMD doesn't flag a problematic piece of code
in:type-resolution
Affects the type resolution code
Milestone
Affects PMD Version: 6.43.0
Rule: UseCollectionIsEmpty
https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#usecollectionisempty
Description:
Please have a look at the following example, variable
list
is a local variable declared with typevar
, assigned by a method invocationgetList()
. The 'real' type oflist
should be inffered asjava.util.List<String>
, an implementation of interfacejava.util.Collection
. Thus it's a good manner to use!list.isEmpty()
instead oflist.size() > 0
at line 8 (at point 1).Code Sample demonstrating the issue:
Expected outcome:
PMD should report a violation at line 8 (at point 1), but doesn't. This is a false-negative.
Running PMD through: [CLI]
The text was updated successfully, but these errors were encountered: