@@ -12,35 +12,35 @@ import java
1212 */
1313predicate conditionCheckMethod ( Method m , boolean checkTrue ) {
1414 conditionCheckMethod ( m , 0 , checkTrue )
15+ }
16+
17+ /**
18+ * Holds if `m` is a non-overridable method that checks that its zero-indexed `argument`
19+ * is equal to `checkTrue` and throws otherwise.
20+ */
21+ predicate conditionCheckMethod ( Method m , int argument , boolean checkTrue ) {
22+ condtionCheckMethodGooglePreconditions ( m , checkTrue ) and argument = 0
1523 or
16- m .getDeclaringType ( ) .hasQualifiedName ( "com.google.common.base" , "Preconditions" ) and
17- checkTrue = true and
18- ( m .hasName ( "checkArgument" ) or m .hasName ( "checkState" ) )
19- or
20- m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.commons.lang3" , "Validate" ) and
21- checkTrue = true and
22- ( m .hasName ( "isTrue" ) or m .hasName ( "validState" ) )
24+ conditionCheckMethodApacheCommonsLang3Validate ( m , checkTrue ) and argument = 0
2325 or
24- m .getDeclaringType ( ) .hasQualifiedName ( "org.junit" , "Assume" ) and
25- checkTrue = true and
26- m .hasName ( "assumeTrue" )
26+ condtionCheckMethodTestingFramework ( m , argument , checkTrue )
2727 or
28- m . getDeclaringType ( ) . hasQualifiedName ( "org.junit.jupiter.api" , "Assertions" ) and
29- (
30- checkTrue = true and m . hasName ( "assertTrue" )
31- or
32- checkTrue = false and m . hasName ( "assertFalse" )
33- )
34- or
35- m . getDeclaringType ( ) . hasQualifiedName ( "org.junit.jupiter.api" , "Assumptions" ) and
36- (
37- checkTrue = true and m . hasName ( "assumeTrue" )
38- or
39- checkTrue = false and m . hasName ( "assumeFalse" )
28+ exists ( Parameter p , MethodAccess ma , int argIndex , boolean ct , Expr arg |
29+ p = m . getParameter ( argument ) and
30+ not m . isOverridable ( ) and
31+ m . getBody ( ) . getStmt ( 0 ) . ( ExprStmt ) . getExpr ( ) = ma and
32+ conditionCheck ( ma , argIndex , ct ) and
33+ ma . getArgument ( argIndex ) = arg and
34+ (
35+ arg . ( LogNotExpr ) . getExpr ( ) . ( VarAccess ) . getVariable ( ) = p and
36+ checkTrue = ct . booleanNot ( )
37+ or
38+ arg . ( VarAccess ) . getVariable ( ) = p and checkTrue = ct
39+ )
4040 )
4141 or
4242 exists ( Parameter p , IfStmt ifstmt , Expr cond |
43- p = m .getParameter ( 0 ) and
43+ p = m .getParameter ( argument ) and
4444 not m .isOverridable ( ) and
4545 p .getType ( ) instanceof BooleanType and
4646 m .getBody ( ) .getStmt ( 0 ) = ifstmt and
@@ -57,12 +57,43 @@ predicate conditionCheckMethod(Method m, boolean checkTrue) {
5757 )
5858}
5959
60+ private predicate condtionCheckMethodGooglePreconditions ( Method m , boolean checkTrue ) {
61+ m .getDeclaringType ( ) .hasQualifiedName ( "com.google.common.base" , "Preconditions" ) and
62+ checkTrue = true and
63+ ( m .hasName ( "checkArgument" ) or m .hasName ( "checkState" ) )
64+ }
65+
66+ private predicate conditionCheckMethodApacheCommonsLang3Validate ( Method m , boolean checkTrue ) {
67+ m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.commons.lang3" , "Validate" ) and
68+ checkTrue = true and
69+ ( m .hasName ( "isTrue" ) or m .hasName ( "validState" ) )
70+ }
71+
6072/**
61- * Holds if `m` is a non-overridable method that checks that its zero-indexed ` argument`
73+ * Holds if `m` is a non-overridable testing framework methopd that checks that its first argument
6274 * is equal to `checkTrue` and throws otherwise.
6375 */
64- predicate conditionCheckMethod ( Method m , int argument , boolean checkTrue ) {
65- conditionCheckMethod ( m , checkTrue ) and argument = 0
76+ private predicate condtionCheckMethodTestingFramework ( Method m , int argument , boolean checkTrue ) {
77+ argument = 0 and
78+ (
79+ m .getDeclaringType ( ) .hasQualifiedName ( "org.junit" , "Assume" ) and
80+ checkTrue = true and
81+ m .hasName ( "assumeTrue" )
82+ or
83+ m .getDeclaringType ( ) .hasQualifiedName ( "org.junit.jupiter.api" , "Assertions" ) and
84+ (
85+ checkTrue = true and m .hasName ( "assertTrue" )
86+ or
87+ checkTrue = false and m .hasName ( "assertFalse" )
88+ )
89+ or
90+ m .getDeclaringType ( ) .hasQualifiedName ( "org.junit.jupiter.api" , "Assumptions" ) and
91+ (
92+ checkTrue = true and m .hasName ( "assumeTrue" )
93+ or
94+ checkTrue = false and m .hasName ( "assumeFalse" )
95+ )
96+ )
6697 or
6798 m .getDeclaringType ( ) .hasQualifiedName ( [ "org.junit" , "org.testng" ] , "Assert" ) and
6899 m .getParameter ( argument ) .getType ( ) instanceof BooleanType and
@@ -71,29 +102,13 @@ predicate conditionCheckMethod(Method m, int argument, boolean checkTrue) {
71102 or
72103 checkTrue = false and m .hasName ( "assertFalse" )
73104 )
74- or
75- exists ( Parameter p , MethodAccess ma , int argIndex , boolean ct , Expr arg |
76- p = m .getParameter ( argument ) and
77- not m .isOverridable ( ) and
78- m .getBody ( ) .getStmt ( 0 ) .( ExprStmt ) .getExpr ( ) = ma and
79- conditionCheck ( ma , argIndex , ct ) and
80- ma .getArgument ( argIndex ) = arg and
81- (
82- arg .( LogNotExpr ) .getExpr ( ) .( VarAccess ) .getVariable ( ) = p and
83- checkTrue = ct .booleanNot ( )
84- or
85- arg .( VarAccess ) .getVariable ( ) = p and checkTrue = ct
86- )
87- )
88105}
89106
90107/**
91108 * Holds if `ma` is an access to a non-overridable method that checks that its
92109 * first argument is equal to `checkTrue` and throws otherwise.
93110 */
94- predicate conditionCheck ( MethodAccess ma , boolean checkTrue ) {
95- conditionCheckMethod ( ma .getMethod ( ) .getSourceDeclaration ( ) , checkTrue )
96- }
111+ predicate conditionCheck ( MethodAccess ma , boolean checkTrue ) { conditionCheck ( ma , 0 , checkTrue ) }
97112
98113/**
99114 * Holds if `ma` is an access to a non-overridable method that checks that its
0 commit comments