FP on S2259 (Null Pointer Dereference) when using MapUtils from Apache Collections

Description

The SE engine is reporting FPs when using Apache commons collection's MapUtils methods which prevent null to be considered.

We should add new hardcoded method behaviors for the following methods:

org.apache.commons.collections4.MapUtils.isEmpty(Map<?, ?>) org.apache.commons.collections4.MapUtils.isNotEmpty(Map<?, ?>) org.apache.commons.collections4.ListUtils.defaultIfNull(List<T>, List<T>) org.apache.commons.collections4.IterableUtils.isEmpty(Iterable<?>) org.apache.commons.collections4.IteratorUtils.isEmpty(Iterator<?>)
public class A { void foo(@javax.annotation.Nullable java.util.Map<String, String> map, String o) { if (org.apache.commons.collections4.MapUtils.isNotEmpty(map)) { map.clear(); // FP S2259 - NPE is not possible } if (!org.apache.commons.collections4.MapUtils.isEmpty(map)) { map.clear(); // FP S2259 - NPE is not possible } } }

Activity

Michael GumowskiJanuary 20, 2021 at 4:10 PM

I added a comment on your PR related to your warning on generated behaviors. Please have a look.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Labels

Fix versions

Due date

Priority

Sentry

Created January 14, 2021 at 9:50 AM
Updated October 16, 2024 at 2:07 PM
Resolved January 25, 2021 at 10:50 AM