Skip to content

Commit bd87be6

Browse files
committed
Refactor to conditionCheckArgument deprecate old method
1 parent b3ee1bd commit bd87be6

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private module ControlFlowGraphImpl {
185185
* Bind `t` to an unchecked exception that may occur in a precondition check.
186186
*/
187187
private predicate uncheckedExceptionFromMethod(MethodAccess ma, ThrowableType t) {
188-
conditionCheck(ma, _, _) and
188+
conditionCheckArgument(ma, _, _) and
189189
(t instanceof TypeError or t instanceof TypeRuntimeException)
190190
}
191191

java/ql/lib/semmle/code/java/controlflow/Guards.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Guard extends ExprParent {
8686
or
8787
this instanceof SwitchCase
8888
or
89-
conditionCheck(this, _, _)
89+
conditionCheckArgument(this, _, _)
9090
}
9191

9292
/** Gets the immediately enclosing callable whose body contains this guard. */
@@ -189,7 +189,7 @@ private predicate switchCaseControls(SwitchCase sc, BasicBlock bb) {
189189
private predicate preconditionBranchEdge(
190190
MethodAccess ma, BasicBlock bb1, BasicBlock bb2, boolean branch
191191
) {
192-
conditionCheck(ma, _, branch) and
192+
conditionCheckArgument(ma, _, branch) and
193193
bb1.getLastNode() = ma.getControlFlowNode() and
194194
bb2 = bb1.getLastNode().getANormalSuccessor()
195195
}

java/ql/lib/semmle/code/java/controlflow/internal/GuardsLogic.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ predicate implies_v1(Guard g1, boolean b1, Guard g2, boolean b2) {
5858
g1.(DefaultCase).getSwitch().getAConstCase() = g2 and b1 = true and b2 = false
5959
or
6060
exists(MethodAccess check, int argIndex | check = g1 |
61-
conditionCheck(check, argIndex, _) and
61+
conditionCheckArgument(check, argIndex, _) and
6262
g2 = check.getArgument(argIndex) and
6363
b1 = [true, false] and
6464
b2 = b1

java/ql/lib/semmle/code/java/controlflow/internal/Preconditions.qll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
import java
88

99
/**
10+
* DEPRECATED: Use `conditionCheckMethodArgument` instead.
1011
* Holds if `m` is a non-overridable method that checks that its first argument
1112
* is equal to `checkTrue` and throws otherwise.
1213
*/
13-
predicate conditionCheckMethod(Method m, boolean checkTrue) {
14-
conditionCheckMethod(m, 0, checkTrue)
14+
deprecated predicate conditionCheckMethod(Method m, boolean checkTrue) {
15+
conditionCheckMethodArgument(m, 0, checkTrue)
1516
}
1617

1718
/**
1819
* Holds if `m` is a non-overridable method that checks that its zero-indexed `argument`
1920
* is equal to `checkTrue` and throws otherwise.
2021
*/
21-
predicate conditionCheckMethod(Method m, int argument, boolean checkTrue) {
22+
predicate conditionCheckMethodArgument(Method m, int argument, boolean checkTrue) {
2223
condtionCheckMethodGooglePreconditions(m, checkTrue) and argument = 0
2324
or
2425
conditionCheckMethodApacheCommonsLang3Validate(m, checkTrue) and argument = 0
@@ -29,7 +30,7 @@ predicate conditionCheckMethod(Method m, int argument, boolean checkTrue) {
2930
p = m.getParameter(argument) and
3031
not m.isOverridable() and
3132
m.getBody().getStmt(0).(ExprStmt).getExpr() = ma and
32-
conditionCheck(ma, argIndex, ct) and
33+
conditionCheckArgument(ma, argIndex, ct) and
3334
ma.getArgument(argIndex) = arg and
3435
(
3536
arg.(LogNotExpr).getExpr().(VarAccess).getVariable() = p and
@@ -105,15 +106,16 @@ private predicate condtionCheckMethodTestingFramework(Method m, int argument, bo
105106
}
106107

107108
/**
109+
* DEPRECATED: Use `conditionCheckArgument` instead.
108110
* Holds if `ma` is an access to a non-overridable method that checks that its
109111
* first argument is equal to `checkTrue` and throws otherwise.
110112
*/
111-
predicate conditionCheck(MethodAccess ma, boolean checkTrue) { conditionCheck(ma, 0, checkTrue) }
113+
deprecated predicate conditionCheck(MethodAccess ma, boolean checkTrue) { conditionCheckArgument(ma, 0, checkTrue) }
112114

113115
/**
114116
* Holds if `ma` is an access to a non-overridable method that checks that its
115117
* zero-indexed `argument` is equal to `checkTrue` and throws otherwise.
116118
*/
117-
predicate conditionCheck(MethodAccess ma, int argument, boolean checkTrue) {
118-
conditionCheckMethod(ma.getMethod().getSourceDeclaration(), argument, checkTrue)
119+
predicate conditionCheckArgument(MethodAccess ma, int argument, boolean checkTrue) {
120+
conditionCheckMethodArgument(ma.getMethod().getSourceDeclaration(), argument, checkTrue)
119121
}

0 commit comments

Comments
 (0)