Skip to content

Commit 492f6eb

Browse files
committed
Model isNotEmpty from Apache Commons Collections
1 parent 2d24387 commit 492f6eb

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java
66
import SSA
77
private import semmle.code.java.controlflow.internal.GuardsLogic
8+
private import semmle.code.java.frameworks.apache.Collections
89
private import RangeUtils
910
private import IntegerGuards
1011

@@ -144,11 +145,7 @@ predicate nullCheckMethod(Method m, boolean branch, boolean isnull) {
144145
branch = false and
145146
isnull = false
146147
or
147-
(
148-
m.getDeclaringType().hasQualifiedName("org.apache.commons.collections4", "CollectionUtils") or
149-
m.getDeclaringType().hasQualifiedName("org.apache.commons.collections", "CollectionUtils")
150-
) and
151-
m.hasName("isNotEmpty") and
148+
m instanceof MethodApacheCollectionsIsNotEmpty and
152149
branch = true and
153150
isnull = false
154151
or
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** Definitions related to the Apache Commons Collections library. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.FlowSteps
5+
private import semmle.code.java.dataflow.ExternalFlow
6+
7+
/**
8+
* The method `isNotEmpty` in either `org.apache.commons.collections.CollectionUtils`
9+
* or `org.apache.commons.collections4.CollectionUtils`.
10+
*/
11+
class MethodApacheCollectionsIsNotEmpty extends Method {
12+
MethodApacheCollectionsIsNotEmpty() {
13+
this.getDeclaringType()
14+
.hasQualifiedName(["org.apache.commons.collections", "org.apache.commons.collections4"],
15+
"CollectionUtils") and
16+
this.hasName("isNotEmpty")
17+
}
18+
}

0 commit comments

Comments
 (0)