@@ -212,33 +212,35 @@ private LocalVariableDecl getCloseableVariable(CloseableInitExpr cie) {
212
212
/**
213
213
* A variable on which a "close" method is called, implicitly or explicitly, directly or indirectly.
214
214
*/
215
- private predicate closeCalled ( Variable v ) {
215
+ private predicate closeCalled ( LocalScopeVariable v ) {
216
216
// `close()` is implicitly called on variables declared or referenced
217
217
// in the resources clause of try-with-resource statements.
218
218
exists ( TryStmt try | try .getAResourceVariable ( ) = v )
219
219
or
220
220
// Otherwise, there should be an explicit call to a method whose name contains "close".
221
221
exists ( MethodCall e |
222
- v = getCloseableVariable ( _) or v instanceof Parameter or v instanceof LocalVariableDecl
223
- |
224
222
e .getMethod ( ) .getName ( ) .toLowerCase ( ) .matches ( "%close%" ) and
225
223
exists ( VarAccess va | va = v .getAnAccess ( ) |
226
224
e .getQualifier ( ) = va or
227
225
e .getAnArgument ( ) = va
228
226
)
229
- or
230
- // The "close" call could happen indirectly inside a helper method of unknown name.
231
- exists ( int i | e .getArgument ( i ) = v .getAnAccess ( ) |
232
- exists ( Parameter p , int j | p .getPosition ( ) = j and p .getCallable ( ) = e .getMethod ( ) |
233
- closeCalled ( p ) and i = j
234
- or
235
- // The helper method could be iterating over a varargs parameter.
236
- exists ( EnhancedForStmt for | for .getExpr ( ) = p .getAnAccess ( ) |
237
- closeCalled ( for .getVariable ( ) .getVariable ( ) )
238
- ) and
239
- p .isVarargs ( ) and
240
- j <= i
241
- )
227
+ )
228
+ or
229
+ // The "close" call could happen indirectly inside a helper method of unknown name.
230
+ exists ( Parameter p |
231
+ closeCalled ( p ) and p .getAnArgument ( ) = v .getAnAccess ( ) and p .getCallable ( ) instanceof Method
232
+ )
233
+ or
234
+ exists ( MethodCall e , int i | e .getArgument ( i ) = v .getAnAccess ( ) |
235
+ exists ( Parameter p , int j |
236
+ p .getPosition ( ) = j and p .getCallable ( ) = e .getMethod ( ) .getSourceDeclaration ( )
237
+ |
238
+ // The helper method could be iterating over a varargs parameter.
239
+ exists ( EnhancedForStmt for | for .getExpr ( ) = p .getAnAccess ( ) |
240
+ closeCalled ( for .getVariable ( ) .getVariable ( ) )
241
+ ) and
242
+ p .isVarargs ( ) and
243
+ j <= i
242
244
)
243
245
)
244
246
}
0 commit comments