Skip to content

Commit 34aa50e

Browse files
committed
Java: Replace some references to basicNullGuard.
1 parent 61b3458 commit 34aa50e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,21 @@ private Method customNullGuard(int index, boolean retval, boolean isnull) {
306306
}
307307

308308
/**
309-
* `guard` is a guard expression that suggests that `v` might be null.
310-
*
311-
* This is equivalent to `guard = basicNullGuard(sameValue(v, _), _, true)`.
309+
* Holds if `guard` is a guard expression that suggests that `e` might be null.
310+
*/
311+
predicate guardSuggestsExprMaybeNull(Expr guard, Expr e) {
312+
guard.(EqualityTest).hasOperands(e, any(NullLiteral n))
313+
or
314+
exists(MethodCall call |
315+
call = guard and
316+
call.getAnArgument() = e and
317+
nullCheckMethod(call.getMethod(), _, true)
318+
)
319+
}
320+
321+
/**
322+
* Holds if `guard` is a guard expression that suggests that `v` might be null.
312323
*/
313324
predicate guardSuggestsVarMaybeNull(Expr guard, SsaVariable v) {
314-
guard = basicNullGuard(sameValue(v, _), _, true)
325+
guardSuggestsExprMaybeNull(guard, sameValue(v, _))
315326
}

java/ql/src/Language Abuse/UselessNullCheck.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import semmle.code.java.controlflow.Guards
1717

1818
from Expr guard, Expr e, Expr reason, string msg
1919
where
20-
guard = basicNullGuard(e, _, true) and
20+
guardSuggestsExprMaybeNull(guard, e) and
2121
e = clearlyNotNullExpr(reason) and
2222
(
2323
if reason instanceof Guard

0 commit comments

Comments
 (0)