use of java.lang.reflect.InvocationTargetException in project che by eclipse.
the class Accessor method invoke.
/**
* Invokes the method with the given method name and arguments.
*
* @param methodName the method name
* @param types the argument types
* @param arguments the method arguments
* @return the method return value
*/
public Object invoke(String methodName, Class[] types, Object[] arguments) {
Method method = null;
try {
method = fClass.getDeclaredMethod(methodName, types);
} catch (SecurityException e) {
fail();
} catch (NoSuchMethodException ex) {
fail();
}
Assert.isNotNull(method);
method.setAccessible(true);
try {
return method.invoke(fInstance, arguments);
} catch (IllegalArgumentException e) {
fail();
} catch (InvocationTargetException e) {
fail();
} catch (IllegalAccessException e) {
fail();
}
return null;
}
use of java.lang.reflect.InvocationTargetException in project che by eclipse.
the class GwtReflectionUtils method callPrivateMethod.
public static <T> T callPrivateMethod(Object target, Method method, Object... args) {
try {
method.setAccessible(true);
Object res = method.invoke(target, args);
return (T) res;
} catch (InvocationTargetException e) {
if (AssertionError.class.isInstance(e.getCause())) {
throw (AssertionError) e.getCause();
} else if (UmbrellaException.class.isInstance(e.getCause())) {
throw new RuntimeException("Error while calling method '" + method.toString() + "'", e.getCause().getCause());
}
throw new RuntimeException("Error while calling method '" + method.toString() + "'", e.getCause());
} catch (Exception e) {
throw new RuntimeException("Unable to call method '" + target.getClass().getSimpleName() + "." + method.getName() + "(..)'", e);
}
}
use of java.lang.reflect.InvocationTargetException in project hackpad by dropbox.
the class VMBridge_jdk13 method newInterfaceProxy.
@Override
protected Object newInterfaceProxy(Object proxyHelper, final ContextFactory cf, final InterfaceAdapter adapter, final Object target, final Scriptable topScope) {
Constructor<?> c = (Constructor<?>) proxyHelper;
InvocationHandler handler = new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) {
return adapter.invoke(cf, target, topScope, method, args);
}
};
Object proxy;
try {
proxy = c.newInstance(new Object[] { handler });
} catch (InvocationTargetException ex) {
throw Context.throwAsScriptRuntimeEx(ex);
} catch (IllegalAccessException ex) {
// Shouls not happen
throw Kit.initCause(new IllegalStateException(), ex);
} catch (InstantiationException ex) {
// Shouls not happen
throw Kit.initCause(new IllegalStateException(), ex);
}
return proxy;
}
use of java.lang.reflect.InvocationTargetException in project hive by apache.
the class UgiMetaStoreClientFactory method createProxy.
private IMetaStoreClient createProxy(final IMetaStoreClient delegate, final String user, final UserGroupInformation authenticatedUser) {
InvocationHandler handler = new AbstractInvocationHandler() {
@Override
protected Object handleInvocation(Object proxy, final Method method, final Object[] args) throws Throwable {
try {
if (!I_META_STORE_CLIENT_METHODS.contains(method) || authenticatedUser == null) {
return method.invoke(delegate, args);
}
try {
return authenticatedUser.doAs(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
return method.invoke(delegate, args);
}
});
} catch (IOException | InterruptedException e) {
throw new TException("PrivilegedExceptionAction failed as user '" + user + "'.", e);
}
} catch (UndeclaredThrowableException | InvocationTargetException e) {
throw e.getCause();
}
}
};
ClassLoader classLoader = IMetaStoreClient.class.getClassLoader();
Class<?>[] interfaces = new Class<?>[] { IMetaStoreClient.class };
Object proxy = Proxy.newProxyInstance(classLoader, interfaces, handler);
return IMetaStoreClient.class.cast(proxy);
}
use of java.lang.reflect.InvocationTargetException in project druid by druid-io.
the class HadoopTask method invokeForeignLoader.
/**
* This method tries to isolate class loading during a Function call
*
* @param clazzName The Class which has a static method called `runTask`
* @param input The input for `runTask`, must have `input.getClass()` be the class of the input for runTask
* @param loader The loader to use as the context class loader during invocation
* @param <InputType> The input type of the method.
* @param <OutputType> The output type of the method. The result of runTask must be castable to this type.
*
* @return The result of the method invocation
*/
public static <InputType, OutputType> OutputType invokeForeignLoader(final String clazzName, final InputType input, final ClassLoader loader) {
log.debug("Launching [%s] on class loader [%s] with input class [%s]", clazzName, loader, input.getClass());
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(loader);
final Class<?> clazz = loader.loadClass(clazzName);
final Method method = clazz.getMethod("runTask", input.getClass());
return (OutputType) method.invoke(null, input);
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException e) {
throw Throwables.propagate(e);
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
Aggregations