Skip to content

Commit

Permalink
Java: Improve NullGuards.clearlyNotNullExpr()
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcono1234 committed Apr 25, 2021
1 parent a7030c7 commit 3812b3e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions java/ql/src/semmle/code/java/dataflow/NullGuards.qll
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ Expr clearlyNotNullExpr(Expr reason) {
or
result instanceof ArrayCreationExpr and reason = result
or
result instanceof FunctionalExpr and reason = result
or
result instanceof TypeLiteral and reason = result
or
result instanceof ThisAccess and reason = result
or
result instanceof StringLiteral and reason = result
or
// Add and AssignAdd performing String concatenation never have null result
result instanceof AddExpr and result.getType() instanceof TypeString and reason = result
or
exists(Field f |
result = f.getAnAccess() and
(f.hasName("TRUE") or f.hasName("FALSE")) and
f.getDeclaringType().hasQualifiedName("java.lang", "Boolean") and
reason = result
)
result instanceof AssignAddExpr and result.getType() instanceof TypeString and reason = result
or
result.getType() instanceof PrimitiveType and reason = result
or
result instanceof CompileTimeConstantExpr and reason = result
or
result.(CastExpr).getExpr() = clearlyNotNullExpr(reason)
or
Expand All @@ -70,6 +72,11 @@ Expr clearlyNotNullExpr(Expr reason) {
(reason = r1 or reason = r2)
)
or
exists(SwitchExpr s |
s = result and
forall(Expr resultExpr | resultExpr = s.getAResult() | resultExpr = clearlyNotNullExpr(reason))
)
or
exists(SsaVariable v, boolean branch, RValue rval, Guard guard |
guard = directNullGuard(v, branch, false) and
guard.controls(rval.getBasicBlock(), branch) and
Expand Down

0 comments on commit 3812b3e

Please sign in to comment.