Menu

#1304 UseCollectionIsEmpty false positive comparing to 1

PMD-5.3.0
closed
None
PMD
3-Major
Bug
2015-04-01
2015-01-07
szetheli
No

This appears to be a regression of [#1230] because the case in question is mentioned in https://sourceforge.net/p/pmd/bugs/1230/

When comparing a collection size to 1, UseCollectionIsEmpty is triggered incorrectly. The problem here is isEmpty is insufficient for this case. I actually want to "do something" if size()==0 or size()==1

public class PMDIsEmptyFalsePositive
{
    public void falsePositive()
    {
        Collection<String> c = new ArrayList<String>();

        if (c.size() <= 1) // false positive
        {
            // do something
        }
    }
}

Related

Issues: #1230

Discussion

  • Andreas Dangel

    Andreas Dangel - 2015-02-21
    • status: open --> in-progress
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
     
  • Andreas Dangel

    Andreas Dangel - 2015-02-22
    • status: in-progress --> closed
     

Log in to post a comment.