@@ -212,33 +212,35 @@ private LocalVariableDecl getCloseableVariable(CloseableInitExpr cie) {
212212/**
213213 * A variable on which a "close" method is called, implicitly or explicitly, directly or indirectly.
214214 */
215- private predicate closeCalled ( Variable v ) {
215+ private predicate closeCalled ( LocalScopeVariable v ) {
216216 // `close()` is implicitly called on variables declared or referenced
217217 // in the resources clause of try-with-resource statements.
218218 exists ( TryStmt try | try .getAResourceVariable ( ) = v )
219219 or
220220 // Otherwise, there should be an explicit call to a method whose name contains "close".
221221 exists ( MethodCall e |
222- v = getCloseableVariable ( _) or v instanceof Parameter or v instanceof LocalVariableDecl
223- |
224222 e .getMethod ( ) .getName ( ) .toLowerCase ( ) .matches ( "%close%" ) and
225223 exists ( VarAccess va | va = v .getAnAccess ( ) |
226224 e .getQualifier ( ) = va or
227225 e .getAnArgument ( ) = va
228226 )
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
242244 )
243245 )
244246}
0 commit comments