Refactor to conditionCheckArgument deprecate old method

This commit is contained in:
Jonathan Leitschuh
2022-03-22 11:56:43 -04:00
parent b3ee1bd313
commit bd87be636a
4 changed files with 13 additions and 11 deletions

View File

@@ -185,7 +185,7 @@ private module ControlFlowGraphImpl {
* Bind `t` to an unchecked exception that may occur in a precondition check.
*/
private predicate uncheckedExceptionFromMethod(MethodAccess ma, ThrowableType t) {
conditionCheck(ma, _, _) and
conditionCheckArgument(ma, _, _) and
(t instanceof TypeError or t instanceof TypeRuntimeException)
}

View File

@@ -86,7 +86,7 @@ class Guard extends ExprParent {
or
this instanceof SwitchCase
or
conditionCheck(this, _, _)
conditionCheckArgument(this, _, _)
}
/** Gets the immediately enclosing callable whose body contains this guard. */
@@ -189,7 +189,7 @@ private predicate switchCaseControls(SwitchCase sc, BasicBlock bb) {
private predicate preconditionBranchEdge(
MethodAccess ma, BasicBlock bb1, BasicBlock bb2, boolean branch
) {
conditionCheck(ma, _, branch) and
conditionCheckArgument(ma, _, branch) and
bb1.getLastNode() = ma.getControlFlowNode() and
bb2 = bb1.getLastNode().getANormalSuccessor()
}

View File

@@ -58,7 +58,7 @@ predicate implies_v1(Guard g1, boolean b1, Guard g2, boolean b2) {
g1.(DefaultCase).getSwitch().getAConstCase() = g2 and b1 = true and b2 = false
or
exists(MethodAccess check, int argIndex | check = g1 |
conditionCheck(check, argIndex, _) and
conditionCheckArgument(check, argIndex, _) and
g2 = check.getArgument(argIndex) and
b1 = [true, false] and
b2 = b1

View File

@@ -7,18 +7,19 @@
import java
/**
* DEPRECATED: Use `conditionCheckMethodArgument` instead.
* Holds if `m` is a non-overridable method that checks that its first argument
* is equal to `checkTrue` and throws otherwise.
*/
predicate conditionCheckMethod(Method m, boolean checkTrue) {
conditionCheckMethod(m, 0, checkTrue)
deprecated predicate conditionCheckMethod(Method m, boolean checkTrue) {
conditionCheckMethodArgument(m, 0, checkTrue)
}
/**
* Holds if `m` is a non-overridable method that checks that its zero-indexed `argument`
* is equal to `checkTrue` and throws otherwise.
*/
predicate conditionCheckMethod(Method m, int argument, boolean checkTrue) {
predicate conditionCheckMethodArgument(Method m, int argument, boolean checkTrue) {
condtionCheckMethodGooglePreconditions(m, checkTrue) and argument = 0
or
conditionCheckMethodApacheCommonsLang3Validate(m, checkTrue) and argument = 0
@@ -29,7 +30,7 @@ predicate conditionCheckMethod(Method m, int argument, boolean checkTrue) {
p = m.getParameter(argument) and
not m.isOverridable() and
m.getBody().getStmt(0).(ExprStmt).getExpr() = ma and
conditionCheck(ma, argIndex, ct) and
conditionCheckArgument(ma, argIndex, ct) and
ma.getArgument(argIndex) = arg and
(
arg.(LogNotExpr).getExpr().(VarAccess).getVariable() = p and
@@ -105,15 +106,16 @@ private predicate condtionCheckMethodTestingFramework(Method m, int argument, bo
}
/**
* DEPRECATED: Use `conditionCheckArgument` instead.
* Holds if `ma` is an access to a non-overridable method that checks that its
* first argument is equal to `checkTrue` and throws otherwise.
*/
predicate conditionCheck(MethodAccess ma, boolean checkTrue) { conditionCheck(ma, 0, checkTrue) }
deprecated predicate conditionCheck(MethodAccess ma, boolean checkTrue) { conditionCheckArgument(ma, 0, checkTrue) }
/**
* Holds if `ma` is an access to a non-overridable method that checks that its
* zero-indexed `argument` is equal to `checkTrue` and throws otherwise.
*/
predicate conditionCheck(MethodAccess ma, int argument, boolean checkTrue) {
conditionCheckMethod(ma.getMethod().getSourceDeclaration(), argument, checkTrue)
predicate conditionCheckArgument(MethodAccess ma, int argument, boolean checkTrue) {
conditionCheckMethodArgument(ma.getMethod().getSourceDeclaration(), argument, checkTrue)
}