-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Java: Consolidate Assertions.qll and Preconditions.qll. #20377
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Improved support for various assertion libraries, in particular JUnit. This affects the control-flow graph slightly, and in turn affects several queries (mainly quality queries). Most queries should see improved precision (new true positives and fewer false positives), in particular `java/constant-comparison`, `java/index-out-of-bounds`, `java/dereferenced-value-may-be-null`, and `java/useless-null-check`. Some medium precision queries like `java/toctou-race-condition` and `java/unreleased-lock` may see mixed result changes (both slight improvements and slight regressions). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ private import RangeUtils | |
| private import IntegerGuards | ||
| private import NullGuards | ||
| private import semmle.code.java.Collections | ||
| private import semmle.code.java.frameworks.Assertions | ||
| private import semmle.code.java.controlflow.internal.Preconditions | ||
|
|
||
| /** Gets an expression that may be `null`. */ | ||
| Expr nullExpr() { | ||
|
|
@@ -140,20 +140,11 @@ private ControlFlowNode varDereference(SsaVariable v, VarAccess va) { | |
| * A `ControlFlowNode` that ensures that the SSA variable is not null in any | ||
| * subsequent use, either by dereferencing it or by an assertion. | ||
| */ | ||
| private ControlFlowNode ensureNotNull(SsaVariable v) { | ||
| result = varDereference(v, _) | ||
| or | ||
| exists(AssertTrueMethod m | result.asCall() = m.getACheck(directNullGuard(v, true, false))) | ||
| or | ||
| exists(AssertFalseMethod m | result.asCall() = m.getACheck(directNullGuard(v, false, false))) | ||
| or | ||
| exists(AssertNotNullMethod m | result.asCall() = m.getACheck(v.getAUse())) | ||
| or | ||
| exists(AssertThatMethod m, MethodCall ma | | ||
| result.asCall() = m.getACheck(v.getAUse()) and ma.getControlFlowNode() = result | ||
| | | ||
| ma.getAnArgument().(MethodCall).getMethod().getName() = "notNullValue" | ||
| ) | ||
| private ControlFlowNode ensureNotNull(SsaVariable v) { result = varDereference(v, _) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the QlDoc needs to be changed as the assertion related logic has been removed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, that needs a slight cleanup. Do you mind if I postpone that to #20367? (Which I'm going to rebase once this is merged) |
||
|
|
||
| private predicate assertFail(BasicBlock bb, ControlFlowNode n) { | ||
| bb = n.getBasicBlock() and | ||
| methodCallUnconditionallyThrows(n.asExpr()) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| /** | ||
| * DEPRECATED. | ||
| * | ||
| * A library providing uniform access to various assertion frameworks. | ||
| * | ||
| * Currently supports `org.junit.Assert`, `junit.framework.*`, | ||
| * `org.junit.jupiter.api.Assertions`, `com.google.common.base.Preconditions`, | ||
| * and `java.util.Objects`. | ||
| */ | ||
| overlay[local?] | ||
| module; | ||
| deprecated module; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice that it is possible to deprecate the entire module! |
||
|
|
||
| import java | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.