Skip to content

Commit 213f5d6

Browse files
committed
Model and use isEmpty from Apache Collections
1 parent 492f6eb commit 213f5d6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

java/ql/src/semmle/code/java/dataflow/NullGuards.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ predicate nullCheckMethod(Method m, boolean branch, boolean isnull) {
145145
branch = false and
146146
isnull = false
147147
or
148+
m instanceof MethodApacheCollectionsIsEmpty and
149+
branch = false and
150+
isnull = false
151+
or
148152
m instanceof MethodApacheCollectionsIsNotEmpty and
149153
branch = true and
150154
isnull = false

java/ql/src/semmle/code/java/frameworks/apache/Collections.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import java
44
private import semmle.code.java.dataflow.FlowSteps
55
private import semmle.code.java.dataflow.ExternalFlow
66

7+
/**
8+
* The method `isNotEmpty` in either `org.apache.commons.collections.CollectionUtils`
9+
* or `org.apache.commons.collections4.CollectionUtils`.
10+
*/
11+
class MethodApacheCollectionsIsEmpty extends Method {
12+
MethodApacheCollectionsIsEmpty() {
13+
this.getDeclaringType()
14+
.hasQualifiedName(["org.apache.commons.collections", "org.apache.commons.collections4"],
15+
"CollectionUtils") and
16+
this.hasName("isEmpty")
17+
}
18+
}
19+
720
/**
821
* The method `isNotEmpty` in either `org.apache.commons.collections.CollectionUtils`
922
* or `org.apache.commons.collections4.CollectionUtils`.

0 commit comments

Comments
 (0)