private Object invokeGeneratorMethod(Method generator, Object... args) { try { return generator.invoke(this, args); } catch (InvocationTargetException e) { throwIfUnchecked(e.getCause()); throw new RuntimeException(e.getCause()); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } }
@Override public void addTransformer(ClassFileTransformer transformer) { try { this.addTransformerMethod.invoke(this.classLoader, transformer); } catch (InvocationTargetException ex) { throw new IllegalStateException("GlassFish addTransformer method threw exception", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not invoke GlassFish addTransformer method", ex); } }
@Override public void addTransformer(ClassFileTransformer transformer) { try { this.addTransformerMethod.invoke(this.classLoader, transformer); } catch (InvocationTargetException ex) { throw new IllegalStateException("Tomcat addTransformer method threw exception", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not invoke Tomcat addTransformer method", ex); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); Method typeVariableMethod = typeVariableMethods.get(methodName); if (typeVariableMethod == null) { throw new UnsupportedOperationException(methodName); } else { try { return typeVariableMethod.invoke(typeVariableImpl, args); } catch (InvocationTargetException e) { throw e.getCause(); } } } }
public ClassLoader getThrowawayClassLoader() { try { Object classFinder = this.getClassFinderMethod.invoke(this.classLoader); Object parent = this.getParentMethod.invoke(this.classLoader); // arguments for 'clone'-like method return (ClassLoader) this.wlGenericClassLoaderConstructor.newInstance(classFinder, parent); } catch (InvocationTargetException ex) { throw new IllegalStateException("WebLogic GenericClassLoader constructor failed", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not construct WebLogic GenericClassLoader", ex); } }
@GwtIncompatible // java.lang.reflect private static Object invokeAccessibleNonThrowingMethod( Method method, Object receiver, Object... params) { try { return method.invoke(receiver, params); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw propagate(e.getCause()); } }
@Override public ClassLoader getThrowawayClassLoader() { try { return new OverridingClassLoader(this.classLoader, (ClassLoader) this.copyMethod.invoke(this.classLoader)); } catch (InvocationTargetException ex) { throw new IllegalStateException("GlassFish copy method threw exception", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not invoke GlassFish copy method", ex); } }
@Override public ClassLoader getThrowawayClassLoader() { try { return new OverridingClassLoader(this.classLoader, (ClassLoader) this.copyMethod.invoke(this.classLoader)); } catch (InvocationTargetException ex) { throw new IllegalStateException("Tomcat copy method threw exception", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not invoke Tomcat copy method", ex); } }
private Throwable getTestResultException(ITestResult testResult) { Throwable testResultException = testResult.getThrowable(); if (testResultException instanceof InvocationTargetException) { testResultException = ((InvocationTargetException) testResultException).getCause(); } return testResultException; }
void invokeSubscriber(Subscription subscription, Object event) { try { subscription.subscriberMethod.method.invoke(subscription.subscriber, event); } catch (InvocationTargetException e) { handleSubscriberException(subscription, event, e.getCause()); } catch (IllegalAccessException e) { throw new IllegalStateException("Unexpected exception", e); } }
public void addTransformer(ClassFileTransformer transformer) { Assert.notNull(transformer, "ClassFileTransformer must not be null"); try { InvocationHandler adapter = new WebSphereClassPreDefinePlugin(transformer); Object adapterInstance = Proxy.newProxyInstance(this.wsPreProcessorClass.getClassLoader(), new Class<?>[] {this.wsPreProcessorClass}, adapter); this.addPreDefinePlugin.invoke(this.classLoader, adapterInstance); } catch (InvocationTargetException ex) { throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not invoke WebSphere addPreDefinePlugin method", ex); } }
public ClassLoader getThrowawayClassLoader() { try { ClassLoader loader = this.cloneConstructor.newInstance(getClassLoader()); // Clear out the transformers (copied as well) List<?> list = (List<?>) this.transformerList.get(loader); list.clear(); return loader; } catch (InvocationTargetException ex) { throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex); } }
public void addTransformer(ClassFileTransformer transformer) { Assert.notNull(transformer, "ClassFileTransformer must not be null"); try { InvocationHandler adapter = new WebLogicClassPreProcessorAdapter(transformer, this.classLoader); Object adapterInstance = Proxy.newProxyInstance(this.wlPreProcessorClass.getClassLoader(), new Class<?>[] {this.wlPreProcessorClass}, adapter); this.addPreProcessorMethod.invoke(this.classLoader, adapterInstance); } catch (InvocationTargetException ex) { throw new IllegalStateException("WebLogic addInstanceClassPreProcessor method threw exception", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not invoke WebLogic addInstanceClassPreProcessor method", ex); } }
@Override public void run() { try { invokeSubscriberMethod(event); } catch (InvocationTargetException e) { bus.handleSubscriberException(e.getCause(), context(event)); } } });
private static Object tryInvoke(Method origin, Object instance, Object[] arguments) throws Throwable { try { return origin.invoke(instance, arguments); } catch (InvocationTargetException exception) { Throwable cause = exception.getCause(); new ConditionalStackTraceFilter().filter(hideRecursiveCall(cause, new Throwable().getStackTrace().length, origin.getDeclaringClass())); throw cause; } }
private Object invokeListMethod(Method method, Object[] args) throws Throwable { try { Object returnValue = method.invoke(delegate, args); mutateDelegate(); return returnValue; } catch (InvocationTargetException e) { throw e.getCause(); } catch (IllegalAccessException e) { throw new AssertionError(e); } }
private void rethrow(String msg, InvocationTargetException ie) { Throwable cause = ie.getCause(); if (cause instanceof AssertionError) { System.err.println(msg); throw (AssertionError) cause; } else { cause.printStackTrace(); fail(msg + cause.getMessage()); } }
@GwtIncompatible("Reflection") public void testAllOverloads_checkNotNull() throws Exception { for (ImmutableList<Class<?>> sig : allSignatures(Object.class)) { Method checkArgumentMethod = Preconditions.class.getMethod("checkNotNull", sig.toArray(new Class<?>[] {})); checkArgumentMethod.invoke( null /* static method */, getParametersForSignature(new Object(), sig)); Object[] failingParams = getParametersForSignature(null, sig); try { checkArgumentMethod.invoke(null /* static method */, failingParams); fail(); } catch (InvocationTargetException ite) { assertFailureCause(ite.getCause(), NullPointerException.class, failingParams); } } }
@GwtIncompatible("Reflection") public void testAllOverloads_checkArgument() throws Exception { for (ImmutableList<Class<?>> sig : allSignatures(boolean.class)) { Method checkArgumentMethod = Preconditions.class.getMethod("checkArgument", sig.toArray(new Class<?>[] {})); checkArgumentMethod.invoke(null /* static method */, getParametersForSignature(true, sig)); Object[] failingParams = getParametersForSignature(false, sig); try { checkArgumentMethod.invoke(null /* static method */, failingParams); fail(); } catch (InvocationTargetException ite) { assertFailureCause(ite.getCause(), IllegalArgumentException.class, failingParams); } } }
@GwtIncompatible("Reflection") public void testAllOverloads_checkState() throws Exception { for (ImmutableList<Class<?>> sig : allSignatures(boolean.class)) { Method checkArgumentMethod = Preconditions.class.getMethod("checkState", sig.toArray(new Class<?>[] {})); checkArgumentMethod.invoke(null /* static method */, getParametersForSignature(true, sig)); Object[] failingParams = getParametersForSignature(false, sig); try { checkArgumentMethod.invoke(null /* static method */, failingParams); fail(); } catch (InvocationTargetException ite) { assertFailureCause(ite.getCause(), IllegalStateException.class, failingParams); } } }