Skip to content

Commit 1acee9d

Browse files
committed
Java: Add some more exception edges to the CFG to facilitate guard wrappers.
1 parent e94f018 commit 1acee9d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,28 @@ private module ControlFlowGraphImpl {
347347
)
348348
}
349349

350+
private predicate methodMayThrow(Method m, ThrowableType t) {
351+
exists(AstNode n |
352+
t = n.(ThrowStmt).getThrownExceptionType() and
353+
not n.(ThrowStmt).getParent().(BlockStmt) = any(Method m0).getBody()
354+
or
355+
uncheckedExceptionFromMethod(n, t)
356+
|
357+
n.getEnclosingStmt().getEnclosingCallable() = m and
358+
not exists(TryStmt try |
359+
exists(try.getACatchClause()) and try.getBlock() = n.getEnclosingStmt().getEnclosingStmt*()
360+
)
361+
)
362+
}
363+
350364
/**
351-
* Bind `t` to an unchecked exception that may occur in a precondition check.
365+
* Bind `t` to an unchecked exception that may occur in a precondition check or guard wrapper.
352366
*/
353367
private predicate uncheckedExceptionFromMethod(MethodCall ma, ThrowableType t) {
354368
conditionCheckArgument(ma, _, _) and
355369
(t instanceof TypeError or t instanceof TypeRuntimeException)
370+
or
371+
methodMayThrow(ma.getMethod(), t)
356372
}
357373

358374
/**

0 commit comments

Comments
 (0)