@@ -63,18 +63,25 @@ predicate disposeReachableFromDisposableCreation(MethodCall disposeCall, Expr di
6363 disposeCall .getTarget ( ) instanceof DisposeMethod
6464}
6565
66- from MethodCall disposeCall , Expr disposableCreation , MethodCall callThatThrows
66+ class MethodCallThatMayThrow extends MethodCall {
67+ MethodCallThatMayThrow ( ) { exists ( getAThrownException ( this .getARuntimeTarget ( ) ) ) }
68+ }
69+
70+ ControlFlowElement getACatchOrFinallyClauseChild ( ) {
71+ exists ( TryStmt ts | result = ts .getACatchClause ( ) or result = ts .getFinally ( ) )
72+ or
73+ result = getACatchOrFinallyClauseChild ( ) .getAChild ( )
74+ }
75+
76+ from MethodCall disposeCall , Expr disposableCreation , MethodCallThatMayThrow callThatThrows
6777where
6878 disposeReachableFromDisposableCreation ( disposeCall , disposableCreation ) and
6979 // The dispose call is not, itself, within a dispose method.
7080 not disposeCall .getEnclosingCallable ( ) instanceof DisposeMethod and
7181 // Dispose call not within a finally or catch block
72- not exists ( TryStmt ts |
73- ts .getACatchClause ( ) .getAChild * ( ) = disposeCall or ts .getFinally ( ) .getAChild * ( ) = disposeCall
74- ) and
82+ not getACatchOrFinallyClauseChild ( ) = disposeCall and
7583 // At least one method call exists between the allocation and disposal that could throw
7684 disposableCreation .getAReachableElement ( ) = callThatThrows and
77- callThatThrows .getAReachableElement ( ) = disposeCall and
78- exists ( getAThrownException ( callThatThrows .getARuntimeTarget ( ) ) )
85+ callThatThrows .getAReachableElement ( ) = disposeCall
7986select disposeCall , "Dispose missed if exception is thrown by $@." , callThatThrows ,
8087 callThatThrows .toString ( )
0 commit comments