Java: Add some more exception edges to the CFG to facilitate guard wrappers.

This commit is contained in:
Anders Schack-Mulligen
2025-08-08 10:31:10 +02:00
parent e94f018e14
commit 492a5ca087

View File

@@ -347,12 +347,28 @@ private module ControlFlowGraphImpl {
)
}
private predicate methodMayThrow(Method m, ThrowableType t) {
exists(AstNode n |
t = n.(ThrowStmt).getThrownExceptionType() and
not n.(ThrowStmt).getParent() = any(Method m0).getBody()
or
uncheckedExceptionFromMethod(n, t)
|
n.getEnclosingStmt().getEnclosingCallable() = m and
not exists(TryStmt try |
exists(try.getACatchClause()) and try.getBlock() = n.getEnclosingStmt().getEnclosingStmt*()
)
)
}
/**
* Bind `t` to an unchecked exception that may occur in a precondition check.
* Bind `t` to an unchecked exception that may occur in a precondition check or guard wrapper.
*/
private predicate uncheckedExceptionFromMethod(MethodCall ma, ThrowableType t) {
conditionCheckArgument(ma, _, _) and
(t instanceof TypeError or t instanceof TypeRuntimeException)
or
methodMayThrow(ma.getMethod(), t)
}
/**