private Object resolve(Object obj) throws Exception { // if there's a readResolve method, call it try { if (_readResolve != null) return _readResolve.invoke(obj, new Object[0]); } catch (InvocationTargetException e) { if (e.getTargetException() != null) throw e; } return obj; }
public Object call(Object instance) throws Exception { try { return method.invoke(instance,arguments); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof Exception) throw (Exception) t; throw e; } }
private IOException handleInvocationTargetException(InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof Error) { throw (Error) t; } if (t instanceof RuntimeException) { throw (RuntimeException) t; } if (t instanceof IOException) { return (IOException) t; } throw new Error(t); }
/** * Perform the invocation and convert InvocationTargetException * into the underlying target exception. */ @Nullable protected Object invokeWithTargetException() throws Exception { try { return invoke(); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof Exception) { throw (Exception) ex.getTargetException(); } if (ex.getTargetException() instanceof Error) { throw (Error) ex.getTargetException(); } throw ex; } }
private void invokeHandlerMethod(MethodInvocation mi, Throwable ex, Method method) throws Throwable { Object[] handlerArgs; if (method.getParameterCount() == 1) { handlerArgs = new Object[] {ex}; } else { handlerArgs = new Object[] {mi.getMethod(), mi.getArguments(), mi.getThis(), ex}; } try { method.invoke(this.throwsAdvice, handlerArgs); } catch (InvocationTargetException targetEx) { throw targetEx.getTargetException(); } }
/** * Handle the given invocation target exception. Should only be called if no * checked exception is expected to be thrown by the target method. * <p>Throws the underlying RuntimeException or Error in case of such a root * cause. Throws an UndeclaredThrowableException otherwise. * @param ex the invocation target exception to handle */ public static void handleInvocationTargetException(InvocationTargetException ex) { rethrowRuntimeException(ex.getTargetException()); }
@Override public void run() { try { ReflectionUtils.makeAccessible(this.method); this.method.invoke(this.target); } catch (InvocationTargetException ex) { ReflectionUtils.rethrowRuntimeException(ex.getTargetException()); } catch (IllegalAccessException ex) { throw new UndeclaredThrowableException(ex); } }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { return call(object,method,args); } catch (InvocationTargetException e) { throw e.getTargetException(); } } }));
@Nullable private static Object invokeJdbcMethod(Method method, @Nullable Object target, @Nullable Object... args) throws SQLException { try { return method.invoke(target, args); } catch (IllegalAccessException ex) { ReflectionUtils.handleReflectionException(ex); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof SQLException) { throw (SQLException) ex.getTargetException(); } ReflectionUtils.handleInvocationTargetException(ex); } throw new IllegalStateException("Should never get here"); }
private void invokePortableRemoteObject(@Nullable Method method) throws RemoteException { if (method != null) { try { method.invoke(null, this.exportedObject); } catch (InvocationTargetException ex) { Throwable targetEx = ex.getTargetException(); if (targetEx instanceof RemoteException) { throw (RemoteException) targetEx; } ReflectionUtils.rethrowRuntimeException(targetEx); } catch (Throwable ex) { throw new IllegalStateException("PortableRemoteObject invocation failed", ex); } } }
@Override public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException { LifecycleMetadata metadata = findLifecycleMetadata(bean.getClass()); try { metadata.invokeDestroyMethods(bean, beanName); } catch (InvocationTargetException ex) { String msg = "Destroy method on bean with name '" + beanName + "' threw an exception"; if (logger.isDebugEnabled()) { logger.warn(msg, ex.getTargetException()); } else { logger.warn(msg + ": " + ex.getTargetException()); } } catch (Throwable ex) { logger.warn("Failed to invoke destroy method on bean with name '" + beanName + "'", ex); } }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { LifecycleMetadata metadata = findLifecycleMetadata(bean.getClass()); try { metadata.invokeInitMethods(bean, beanName); } catch (InvocationTargetException ex) { throw new BeanCreationException(beanName, "Invocation of init method failed", ex.getTargetException()); } catch (Throwable ex) { throw new BeanCreationException(beanName, "Failed to invoke init method", ex); } return bean; }
private void setThreadCallbacks(Callback[] callbacks) { try { setThreadCallbacks.invoke(generatedClass, (Object) callbacks); } catch (IllegalAccessException e) { throw new CodeGenerationException(e); } catch (InvocationTargetException e) { throw new CodeGenerationException(e.getTargetException()); } } }
protected static Object invokeVfsMethod(Method method, @Nullable Object target, Object... args) throws IOException { try { return method.invoke(target, args); } catch (InvocationTargetException ex) { Throwable targetEx = ex.getTargetException(); if (targetEx instanceof IOException) { throw (IOException) targetEx; } ReflectionUtils.handleInvocationTargetException(ex); } catch (Exception ex) { ReflectionUtils.handleReflectionException(ex); } throw new IllegalStateException("Invalid code path reached"); }
@Override @Nullable protected TransactionManager retrieveTransactionManager() throws TransactionSystemException { Object helper = loadWebLogicTransactionHelper(); try { logger.trace("Retrieving JTA TransactionManager from WebLogic TransactionHelper"); Method getTransactionManagerMethod = helper.getClass().getMethod("getTransactionManager"); return (TransactionManager) getTransactionManagerMethod.invoke(this.transactionHelper); } catch (InvocationTargetException ex) { throw new TransactionSystemException( "WebLogic's TransactionHelper.getTransactionManager() method failed", ex.getTargetException()); } catch (Exception ex) { throw new TransactionSystemException( "Could not invoke WebLogic's TransactionHelper.getTransactionManager() method", ex); } }
@Override @Nullable protected UserTransaction retrieveUserTransaction() throws TransactionSystemException { Object helper = loadWebLogicTransactionHelper(); try { logger.trace("Retrieving JTA UserTransaction from WebLogic TransactionHelper"); Method getUserTransactionMethod = helper.getClass().getMethod("getUserTransaction"); return (UserTransaction) getUserTransactionMethod.invoke(this.transactionHelper); } catch (InvocationTargetException ex) { throw new TransactionSystemException( "WebLogic's TransactionHelper.getUserTransaction() method failed", ex.getTargetException()); } catch (Exception ex) { throw new TransactionSystemException( "Could not invoke WebLogic's TransactionHelper.getUserTransaction() method", ex); } }
@Override public void run() { try { invoke(); } catch (InvocationTargetException ex) { logger.error(getInvocationFailureMessage(), ex.getTargetException()); // Do not throw exception, else the main loop of the scheduler might stop! } catch (Throwable ex) { logger.error(getInvocationFailureMessage(), ex); // Do not throw exception, else the main loop of the scheduler might stop! } }
protected Object invokeAdviceMethodWithGivenArgs(Object[] args) throws Throwable { Object[] actualArgs = args; if (this.aspectJAdviceMethod.getParameterCount() == 0) { actualArgs = null; } try { ReflectionUtils.makeAccessible(this.aspectJAdviceMethod); // TODO AopUtils.invokeJoinpointUsingReflection return this.aspectJAdviceMethod.invoke(this.aspectInstanceFactory.getAspectInstance(), actualArgs); } catch (IllegalArgumentException ex) { throw new AopInvocationException("Mismatch on arguments to advice method [" + this.aspectJAdviceMethod + "]; pointcut expression [" + this.pointcut.getPointcutExpression() + "]", ex); } catch (InvocationTargetException ex) { throw ex.getTargetException(); } }
@Override protected void runTest() throws Throwable { Monitor monitor = new Monitor(fair); FlagGuard guard = new FlagGuard(monitor); Object[] arguments = (timed ? new Object[] {guard, 0L, TimeUnit.MILLISECONDS} : new Object[] {guard}); try { method.invoke(monitor, arguments); fail("expected IllegalMonitorStateException"); } catch (InvocationTargetException e) { assertEquals(IllegalMonitorStateException.class, e.getTargetException().getClass()); } } };
private void doTest(Method rsetMethod, Method rowsetMethod, Object arg, Object ret) throws Exception { if (arg instanceof String) { given(resultSet.findColumn((String) arg)).willReturn(1); given(rsetMethod.invoke(resultSet, 1)).willReturn(ret).willThrow(new SQLException("test")); } else { given(rsetMethod.invoke(resultSet, arg)).willReturn(ret).willThrow(new SQLException("test")); } rowsetMethod.invoke(rowSet, arg); try { rowsetMethod.invoke(rowSet, arg); fail("InvalidResultSetAccessException should have been thrown"); } catch (InvocationTargetException ex) { assertEquals(InvalidResultSetAccessException.class, ex.getTargetException().getClass()); } }