Missing statement to record cause of InvocationTargetException Info

Missing statements to record the underlying cause of InvocationTargetException might make the code harder to debug.

Detector ID
java/missing-getcause-on-invocationtargetexception@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-

Noncompliant example

1public Object invokeMethodNonCompliant(Method method, Object[] args) throws Throwable {
2    // Noncompliant: InvocationTargetException is not caught.
3    return method.invoke(args);
4}

Compliant example

1public Object invokeMethodCompliant(Object proxy, Method method, Object[] args) throws Throwable {
2    try {
3        // Compliant: InvocationTargetException is caught and e.getCause() is propagated further.
4        Object returnValue = method.invoke(args);
5        return returnValue;
6    } catch (InvocationTargetException e) {
7        throw e.getTargetException();
8    }
9}