Model isNotEmpty from Apache Commons Collections

This commit is contained in:
Owen Mansel-Chan
2021-06-16 12:13:55 +01:00
parent 2d24387e9e
commit 492f6ebc7c
2 changed files with 20 additions and 5 deletions

View File

@@ -5,6 +5,7 @@
import java
import SSA
private import semmle.code.java.controlflow.internal.GuardsLogic
private import semmle.code.java.frameworks.apache.Collections
private import RangeUtils
private import IntegerGuards
@@ -144,11 +145,7 @@ predicate nullCheckMethod(Method m, boolean branch, boolean isnull) {
branch = false and
isnull = false
or
(
m.getDeclaringType().hasQualifiedName("org.apache.commons.collections4", "CollectionUtils") or
m.getDeclaringType().hasQualifiedName("org.apache.commons.collections", "CollectionUtils")
) and
m.hasName("isNotEmpty") and
m instanceof MethodApacheCollectionsIsNotEmpty and
branch = true and
isnull = false
or

View File

@@ -0,0 +1,18 @@
/** Definitions related to the Apache Commons Collections library. */
import java
private import semmle.code.java.dataflow.FlowSteps
private import semmle.code.java.dataflow.ExternalFlow
/**
* The method `isNotEmpty` in either `org.apache.commons.collections.CollectionUtils`
* or `org.apache.commons.collections4.CollectionUtils`.
*/
class MethodApacheCollectionsIsNotEmpty extends Method {
MethodApacheCollectionsIsNotEmpty() {
this.getDeclaringType()
.hasQualifiedName(["org.apache.commons.collections", "org.apache.commons.collections4"],
"CollectionUtils") and
this.hasName("isNotEmpty")
}
}