diff --git a/java/ql/src/semmle/code/java/dataflow/NullGuards.qll b/java/ql/src/semmle/code/java/dataflow/NullGuards.qll index 589b1f7c49f5f..7f23a04378f1c 100644 --- a/java/ql/src/semmle/code/java/dataflow/NullGuards.qll +++ b/java/ql/src/semmle/code/java/dataflow/NullGuards.qll @@ -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 @@ -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