NIFI-43: Do not throw InvocationTargetException if it is wrapping a RuntimeException; instead just throw the RuntimeException

This commit is contained in:
Mark Payne 2014-12-15 13:14:42 -05:00
parent 73cc6cbe28
commit e04a55d3a5
1 changed files with 40 additions and 32 deletions

View File

@ -42,6 +42,7 @@ public class ReflectionUtils {
* @throws IllegalAccessException * @throws IllegalAccessException
*/ */
public static void invokeMethodsWithAnnotation(final Class<? extends Annotation> annotation, final Object instance, final Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { public static void invokeMethodsWithAnnotation(final Class<? extends Annotation> annotation, final Object instance, final Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
try {
for (final Method method : instance.getClass().getMethods()) { for (final Method method : instance.getClass().getMethods()) {
if (method.isAnnotationPresent(annotation)) { if (method.isAnnotationPresent(annotation)) {
final boolean isAccessible = method.isAccessible(); final boolean isAccessible = method.isAccessible();
@ -80,6 +81,13 @@ public class ReflectionUtils {
} }
} }
} }
} catch (final InvocationTargetException ite) {
if ( ite.getCause() instanceof RuntimeException ) {
throw (RuntimeException) ite.getCause();
} else {
throw ite;
}
}
} }
/** /**