Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
Java: Fix assert CFG by properly tagging the false successor.#19883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -100,7 +100,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 { | ||
| @@ -204,6 +205,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; | ||
| @@ -327,7 +347,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 | ||
| @@ -1123,12 +1153,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 | ||
| @@ -1547,7 +1572,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 | ||
| ) | ||
aschackmull marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| or | ||
| // When expressions: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1 java/ql/test/query-tests/RangeAnalysis/ArrayIndexOutOfBounds.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.