Skip to content

Commit 6a65c46

Browse files
committed
Java/Shared: Share more 'isNull' computations.
1 parent 90fbacc commit 6a65c46

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private module Input implements TypeFlowInput<J::Location> {
125125
/**
126126
* Holds if `null` is the only value that flows to `n`.
127127
*/
128-
predicate isNull(TypeFlowNode n) {
128+
predicate isNullValue(TypeFlowNode n) {
129129
n.asExpr() instanceof NullLiteral
130130
or
131131
exists(LocalVariableDeclExpr decl |
@@ -134,9 +134,7 @@ private module Input implements TypeFlowInput<J::Location> {
134134
not exists(decl.getInit())
135135
)
136136
or
137-
exists(TypeFlowNode mid | isNull(mid) and step(mid, n))
138-
or
139-
forex(TypeFlowNode mid | joinStep0(mid, n) | isNull(mid)) and
137+
forex(TypeFlowNode mid | joinStep0(mid, n) | Make<J::Location, Input>::isNull(mid)) and
140138
// Fields that are never assigned a non-null value are probably set by
141139
// reflection and are thus not always null.
142140
not exists(n.asField())

shared/typeflow/codeql/typeflow/TypeFlow.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ signature module TypeFlowInput<LocationSig Location> {
3939
*/
4040
predicate step(TypeFlowNode n1, TypeFlowNode n2);
4141

42-
/**
43-
* Holds if `null` is the only value that flows to `n`.
44-
*/
45-
predicate isNull(TypeFlowNode n);
42+
/** Holds if `n` represents a `null` value. */
43+
predicate isNullValue(TypeFlowNode n);
4644

4745
/** A type. */
4846
class Type {

shared/typeflow/codeql/typeflow/internal/TypeFlowImpl.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ private import codeql.util.Unit
55
module TypeFlow<LocationSig Location, TypeFlowInput<Location> I> {
66
private import I
77

8+
/** Holds if `null` is the only value that flows to `n`. */
9+
predicate isNull(TypeFlowNode n) {
10+
isNullValue(n)
11+
or
12+
exists(TypeFlowNode mid | isNull(mid) and step(mid, n))
13+
}
14+
815
/**
916
* Holds if data can flow from `n1` to `n2` in one step, `n1` is not necessarily
1017
* functionally determined by `n2`, and `n1` might take a non-null value.

0 commit comments

Comments
 (0)