/** * Invokes the method on {@code target}. If the method does not exist or is not public then * {@code null} is returned. Any RuntimeException thrown by the method is thrown, checked * exceptions are wrapped in an {@link AssertionError}. * * @throws IllegalArgumentException if the arguments are invalid */ public Object invokeOptionalWithoutCheckedException(T target, Object... args) { try { return invokeOptional(target, args); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } AssertionError error = new AssertionError("Unexpected exception"); error.initCause(targetException); throw error; } }
/** * Invokes the method on {@code target}. If the method does not exist or is not public then * {@code null} is returned. Any RuntimeException thrown by the method is thrown, checked * exceptions are wrapped in an {@link AssertionError}. * * @throws IllegalArgumentException if the arguments are invalid */ public Object invokeOptionalWithoutCheckedException(T target, Object... args) { try { return invokeOptional(target, args); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } AssertionError error = new AssertionError("Unexpected exception"); error.initCause(targetException); throw error; } }