Java - squid:S2259 - False positive with CollectionUtils.isEmpty

219 views
Skip to first unread message

Vincent Privat

unread,
Apr 19, 2017, 6:25:18 AM4/19/17
to SonarQube
Hi,

The following code triggers squid:S2259 (Null pointers should not be dereferenced):

import org.apache.commons.collections.CollectionUtils;

        List<Object> objects = getSomething();
        if (CollectionUtils.isEmpty(objects)) { // returns true if objects is null
            doSomething();
        } else if (objects.size() == 1) { // squid:S2259 here => FP
            doSomethingElse();
        }

Can you please handle the fact that CollectionUtils.isEmpty() returns true for null collections?

Best regards,
Vincent

Nicolas Peru

unread,
May 10, 2017, 8:44:52 AM5/10/17
to Vincent Privat, SonarQube
Hi, 
Indeed, 
ticket created to handle the issue : https://jira.sonarsource.com/browse/SONARJAVA-2283 

Even if ultimately we want to generate those rather than hardcoding them. But let's hardcode it firts.

Cheers, 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/16a8b091-2408-4817-9caa-ae02f333c340%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource
Reply all
Reply to author
Forward
0 new messages