Skip to content

Commit f9ffee0

Browse files
committed
Java: Minor nullness cleanup.
1 parent 2743fc0 commit f9ffee0

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -119,39 +119,18 @@ private ControlFlowNode varDereference(SsaVariable v, VarAccess va) {
119119
}
120120

121121
/**
122-
* A `ControlFlowNode` that ensures that the SSA variable is not null in any
123-
* subsequent use, either by dereferencing it or by an assertion.
124-
*/
125-
private ControlFlowNode ensureNotNull(SsaVariable v) { result = varDereference(v, _) }
126-
127-
private predicate assertFail(BasicBlock bb, ControlFlowNode n) {
128-
bb = n.getBasicBlock() and
129-
methodCallUnconditionallyThrows(n.asExpr())
130-
}
131-
132-
/**
133-
* A variable dereference that cannot be reached by a `null` value, because of an earlier
134-
* dereference or assertion in the same `BasicBlock`.
135-
*/
136-
private predicate unreachableVarDereference(BasicBlock bb, SsaVariable v, ControlFlowNode varDeref) {
137-
exists(ControlFlowNode n, int i, int j |
138-
(n = ensureNotNull(v) or assertFail(bb, n)) and
139-
varDeref = varDereference(v, _) and
140-
bb.getNode(i) = n and
141-
bb.getNode(j) = varDeref and
142-
i < j
143-
)
144-
}
145-
146-
/**
147-
* The first dereference of a variable in a given `BasicBlock` excluding those dereferences
148-
* that are preceded by a not-null assertion or a trivially failing assertion.
122+
* The first dereference of a variable in a given `BasicBlock`.
149123
*/
150124
private predicate firstVarDereferenceInBlock(BasicBlock bb, SsaVariable v, VarAccess va) {
151125
exists(ControlFlowNode n |
152126
varDereference(v, va) = n and
153127
n.getBasicBlock() = bb and
154-
not unreachableVarDereference(bb, v, n)
128+
n =
129+
min(ControlFlowNode n0, int i |
130+
varDereference(v, _) = n0 and bb.getNode(i) = n0
131+
|
132+
n0 order by i
133+
)
155134
)
156135
}
157136

0 commit comments

Comments
 (0)