mirror of
https://github.com/github/codeql.git
synced 2026-02-28 04:43:42 +01:00
Merge remote-tracking branch 'github/main' into kaspersv/overlay-java-annotations
This commit is contained in:
@@ -102,7 +102,8 @@ module ControlFlow {
|
||||
private newtype TNode =
|
||||
TExprNode(Expr e) { hasControlFlow(e) } or
|
||||
TStmtNode(Stmt s) or
|
||||
TExitNode(Callable c) { exists(c.getBody()) }
|
||||
TExitNode(Callable c) { exists(c.getBody()) } or
|
||||
TAssertThrowNode(AssertStmt s)
|
||||
|
||||
/** A node in the expression-level control-flow graph. */
|
||||
class Node extends TNode {
|
||||
@@ -206,6 +207,25 @@ module ControlFlow {
|
||||
/** Gets the source location for this element. */
|
||||
override Location getLocation() { result = c.getLocation() }
|
||||
}
|
||||
|
||||
/** A control flow node indicating a failing assertion. */
|
||||
class AssertThrowNode extends Node, TAssertThrowNode {
|
||||
AssertStmt s;
|
||||
|
||||
AssertThrowNode() { this = TAssertThrowNode(s) }
|
||||
|
||||
override Stmt getEnclosingStmt() { result = s }
|
||||
|
||||
override Callable getEnclosingCallable() { result = s.getEnclosingCallable() }
|
||||
|
||||
override ExprParent getAstNode() { result = s }
|
||||
|
||||
/** Gets a textual representation of this element. */
|
||||
override string toString() { result = "Assert Throw" }
|
||||
|
||||
/** Gets the source location for this element. */
|
||||
override Location getLocation() { result = s.getLocation() }
|
||||
}
|
||||
}
|
||||
|
||||
class ControlFlowNode = ControlFlow::Node;
|
||||
@@ -329,7 +349,17 @@ private module ControlFlowGraphImpl {
|
||||
)
|
||||
}
|
||||
|
||||
private ThrowableType assertionError() { result.hasQualifiedName("java.lang", "AssertionError") }
|
||||
private ThrowableType actualAssertionError() {
|
||||
result.hasQualifiedName("java.lang", "AssertionError")
|
||||
}
|
||||
|
||||
private ThrowableType assertionError() {
|
||||
result = actualAssertionError()
|
||||
or
|
||||
// In case `AssertionError` is not extracted, we use `Error` as a fallback.
|
||||
not exists(actualAssertionError()) and
|
||||
result.hasQualifiedName("java.lang", "Error")
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an exception type that may be thrown during execution of the
|
||||
@@ -1125,12 +1155,7 @@ private module ControlFlowGraphImpl {
|
||||
or
|
||||
// `assert` statements may throw
|
||||
completion = ThrowCompletion(assertionError()) and
|
||||
(
|
||||
last(assertstmt.getMessage(), last, NormalCompletion())
|
||||
or
|
||||
not exists(assertstmt.getMessage()) and
|
||||
last(assertstmt.getExpr(), last, BooleanCompletion(false, _))
|
||||
)
|
||||
last.(AssertThrowNode).getAstNode() = assertstmt
|
||||
)
|
||||
or
|
||||
// `throw` statements or throwing calls give rise to `Throw` completion
|
||||
@@ -1549,7 +1574,15 @@ private module ControlFlowGraphImpl {
|
||||
or
|
||||
last(assertstmt.getExpr(), n, completion) and
|
||||
completion = BooleanCompletion(false, _) and
|
||||
result = first(assertstmt.getMessage())
|
||||
(
|
||||
result = first(assertstmt.getMessage())
|
||||
or
|
||||
not exists(assertstmt.getMessage()) and
|
||||
result.(AssertThrowNode).getAstNode() = assertstmt
|
||||
)
|
||||
or
|
||||
last(assertstmt.getMessage(), n, NormalCompletion()) and
|
||||
result.(AssertThrowNode).getAstNode() = assertstmt
|
||||
)
|
||||
or
|
||||
// When expressions:
|
||||
|
||||
Reference in New Issue
Block a user