@@ -242,16 +242,20 @@ Guard nullGuard(SsaVariable v, boolean branch, boolean isnull) {
242
242
}
243
243
244
244
/**
245
- * A return statement that on a return value of `retval` allows the conclusion that the
246
- * parameter `p` either is null or non-null as specified by `isnull`.
245
+ * A return statement in a non-overridable method that on a return value of
246
+ * `retval` allows the conclusion that the parameter `p` either is null or
247
+ * non-null as specified by `isnull`.
247
248
*/
248
249
private predicate validReturnInCustomNullGuard (
249
250
ReturnStmt ret , Parameter p , boolean retval , boolean isnull
250
251
) {
251
252
exists ( Method m |
252
253
ret .getEnclosingCallable ( ) = m and
253
254
p .getCallable ( ) = m and
254
- m .getReturnType ( ) .( PrimitiveType ) .hasName ( "boolean" )
255
+ m .getReturnType ( ) .( PrimitiveType ) .hasName ( "boolean" ) and
256
+ not p .isVarargs ( ) and
257
+ p .getType ( ) instanceof RefType and
258
+ not m .isOverridable ( )
255
259
) and
256
260
exists ( SsaImplicitInit ssa | ssa .isParameterDefinition ( p ) |
257
261
nullGuardedReturn ( ret , ssa , isnull ) and
@@ -267,21 +271,22 @@ private predicate nullGuardedReturn(ReturnStmt ret, SsaImplicitInit ssa, boolean
267
271
)
268
272
}
269
273
274
+ pragma [ nomagic]
275
+ private Method returnStmtGetEnclosingCallable ( ReturnStmt ret ) {
276
+ ret .getEnclosingCallable ( ) = result
277
+ }
278
+
270
279
/**
271
280
* Gets a non-overridable method with a boolean return value that performs a null-check
272
281
* on the `index`th parameter. A return value equal to `retval` allows us to conclude
273
282
* that the argument either is null or non-null as specified by `isnull`.
274
283
*/
275
284
private Method customNullGuard ( int index , boolean retval , boolean isnull ) {
276
285
exists ( Parameter p |
277
- result .getReturnType ( ) .( PrimitiveType ) .hasName ( "boolean" ) and
278
- not result .isOverridable ( ) and
279
286
p .getCallable ( ) = result and
280
- not p .isVarargs ( ) and
281
- p .getType ( ) instanceof RefType and
282
287
p .getPosition ( ) = index and
283
288
forex ( ReturnStmt ret |
284
- ret . getEnclosingCallable ( ) = result and
289
+ returnStmtGetEnclosingCallable ( ret ) = result and
285
290
exists ( Expr res | res = ret .getResult ( ) |
286
291
not res .( BooleanLiteral ) .getBooleanValue ( ) = retval .booleanNot ( )
287
292
)
0 commit comments