@@ -29,7 +29,8 @@ ExceptionClass getAThrownException(Method m) {
2929 or
3030 exists ( ControlFlowElement cfe |
3131 cfe = any ( ThrowElement te | result = te .getExpr ( ) .getType ( ) ) or
32- cfe = any ( MethodCall mc | result = getAThrownException ( mc .getARuntimeTarget ( ) ) ) |
32+ cfe = any ( MethodCall mc | result = getAThrownException ( mc .getARuntimeTarget ( ) ) )
33+ |
3334 cfe .getEnclosingCallable ( ) = m and
3435 not isTriedAgainstException ( cfe , result )
3536 )
@@ -39,7 +40,7 @@ ExceptionClass getAThrownException(Method m) {
3940 * Holds if control flow element is tried against throwing an exception of type
4041 * `ec`.
4142 */
42- pragma [ noinline]
43+ pragma [ noinline]
4344predicate isTriedAgainstException ( ControlFlowElement cfe , ExceptionClass ec ) {
4445 ( cfe instanceof ThrowElement or cfe instanceof MethodCall ) and
4546 exists ( TryStmt ts |
@@ -53,22 +54,27 @@ predicate isTriedAgainstException(ControlFlowElement cfe, ExceptionClass ec) {
5354 */
5455predicate disposeReachableFromDisposableCreation ( MethodCall disposeCall , Expr disposableCreation ) {
5556 // The qualifier of the Dispose call flows from something that introduced a disposable into scope
56- ( disposableCreation instanceof LocalScopeDisposableCreation or disposableCreation instanceof MethodCall )
57- and DataFlow:: localFlowStep + ( DataFlow:: exprNode ( disposableCreation ) , DataFlow:: exprNode ( disposeCall .getQualifier ( ) ) )
58- and disposeCall .getTarget ( ) instanceof DisposeMethod
57+ (
58+ disposableCreation instanceof LocalScopeDisposableCreation or
59+ disposableCreation instanceof MethodCall
60+ ) and
61+ DataFlow:: localFlowStep + ( DataFlow:: exprNode ( disposableCreation ) ,
62+ DataFlow:: exprNode ( disposeCall .getQualifier ( ) ) ) and
63+ disposeCall .getTarget ( ) instanceof DisposeMethod
5964}
6065
61-
6266from MethodCall disposeCall , Expr disposableCreation , MethodCall callThatThrows
6367where
64- disposeReachableFromDisposableCreation ( disposeCall , disposableCreation )
68+ disposeReachableFromDisposableCreation ( disposeCall , disposableCreation ) and
6569 // The dispose call is not, itself, within a dispose method.
66- and not disposeCall .getEnclosingCallable ( ) instanceof DisposeMethod
70+ not disposeCall .getEnclosingCallable ( ) instanceof DisposeMethod and
6771 // Dispose call not within a finally or catch block
68- and not exists ( TryStmt ts |
69- ts .getACatchClause ( ) .getAChild * ( ) = disposeCall or ts .getFinally ( ) .getAChild * ( ) = disposeCall )
72+ not exists ( TryStmt ts |
73+ ts .getACatchClause ( ) .getAChild * ( ) = disposeCall or ts .getFinally ( ) .getAChild * ( ) = disposeCall
74+ ) and
7075 // At least one method call exists between the allocation and disposal that could throw
71- and disposableCreation .getAReachableElement ( ) = callThatThrows
72- and callThatThrows .getAReachableElement ( ) = disposeCall
73- and exists ( getAThrownException ( callThatThrows .getARuntimeTarget ( ) ) )
74- select disposeCall , "Dispose missed if exception is thrown by $@." , callThatThrows , callThatThrows .toString ( )
76+ disposableCreation .getAReachableElement ( ) = callThatThrows and
77+ callThatThrows .getAReachableElement ( ) = disposeCall and
78+ exists ( getAThrownException ( callThatThrows .getARuntimeTarget ( ) ) )
79+ select disposeCall , "Dispose missed if exception is thrown by $@." , callThatThrows ,
80+ callThatThrows .toString ( )
0 commit comments