@@ -94,6 +94,34 @@ Expr clearlyNotNullExpr() { result = clearlyNotNullExpr(_) }
9494/** Holds if `v` is an SSA variable that is provably not `null`. */
9595predicate clearlyNotNull ( SsaVariable v ) { clearlyNotNull ( v , _) }
9696
97+ /**
98+ * Holds if the evaluation of a call to `m` resulting in the value `branch`
99+ * implies that the argument to the call is guaranteed to be null if `isnull`
100+ * is true, and non-null if `isnull` is false.
101+ */
102+ predicate nullCheckMethod ( Method m , boolean branch , boolean isnull ) {
103+ exists ( boolean polarity |
104+ m .getDeclaringType ( ) .hasQualifiedName ( "java.util" , "Objects" ) and
105+ (
106+ m .hasName ( "isNull" ) and polarity = true
107+ or
108+ m .hasName ( "nonNull" ) and polarity = false
109+ ) and
110+ (
111+ branch = true and isnull = polarity
112+ or
113+ branch = false and isnull = polarity .booleanNot ( )
114+ )
115+ )
116+ or
117+ m instanceof EqualsMethod and branch = true and isnull = false
118+ or
119+ m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.commons.lang3" , "StringUtils" ) and
120+ m .hasName ( "isBlank" ) and
121+ branch = false and
122+ isnull = false
123+ }
124+
97125/**
98126 * Gets an expression that directly tests whether a given expression, `e`, is null or not.
99127 *
@@ -114,29 +142,10 @@ Expr basicNullGuard(Expr e, boolean branch, boolean isnull) {
114142 or
115143 result .( InstanceOfExpr ) .getExpr ( ) = e and branch = true and isnull = false
116144 or
117- exists ( MethodAccess call , Method m , boolean polarity |
118- call = result and
119- call .getAnArgument ( ) = e and
120- call .getMethod ( ) = m and
121- m .getDeclaringType ( ) .hasQualifiedName ( "java.util" , "Objects" ) and
122- (
123- m .hasName ( "isNull" ) and polarity = true
124- or
125- m .hasName ( "nonNull" ) and polarity = false
126- ) and
127- (
128- branch = true and isnull = polarity
129- or
130- branch = false and isnull = polarity .booleanNot ( )
131- )
132- )
133- or
134145 exists ( MethodAccess call |
135146 call = result and
136147 call .getAnArgument ( ) = e and
137- call .getMethod ( ) instanceof EqualsMethod and
138- branch = true and
139- isnull = false
148+ nullCheckMethod ( call .getMethod ( ) , branch , isnull )
140149 )
141150 or
142151 exists ( EqualityTest eqtest |
0 commit comments