mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Java: account for generic exceptions in java/unreachable-catch-clause
This commit is contained in:
@@ -47,7 +47,10 @@ RefType getAThrownExceptionType(TryStmt t) {
|
||||
t.getBlock() = call.getEnclosingStmt().getParent*() or
|
||||
t.getAResourceDecl() = call.getEnclosingStmt()
|
||||
|
|
||||
call.getCallee().getAnException() = e and
|
||||
(
|
||||
call.getCallee().getAnException() = e or
|
||||
call.(GenericCall).getATypeArgument(call.getCallee().getAnException().getType()) = e.getType()
|
||||
) and
|
||||
not caughtInside(t, call.getEnclosingStmt(), e.getType()) and
|
||||
result = e.getType()
|
||||
) or
|
||||
|
||||
@@ -68,6 +68,14 @@ public class PartiallyMaskedCatchTest {
|
||||
} catch (IOException e) {
|
||||
// reachable: IOException is thrown by getClosableThing()
|
||||
}
|
||||
|
||||
try (ClosableThing thing = new ClosableThing()) {
|
||||
genericThrowingMethod(IOException.class);
|
||||
} catch (ExceptionA e) {
|
||||
// reachable: ExceptionA is thrown by implicit invocation of CloseableThing.close()
|
||||
} catch (IOException e) {
|
||||
// reachable: IOException is thrown by invocation of genericThrowingMethod(IOException.class)
|
||||
}
|
||||
}
|
||||
|
||||
public static ClosableThing getClosableThing() throws IOException {
|
||||
@@ -94,4 +102,6 @@ public class PartiallyMaskedCatchTest {
|
||||
throws ClassNotFoundException,
|
||||
NoSuchMethodException, InstantiationException, IllegalAccessException,
|
||||
InvocationTargetException {}
|
||||
|
||||
public static <E extends Exception> void genericThrowingMethod(Class<E> c) throws E {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user