Search in sources :

Example 71 with InvocationTargetException

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;
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 72 with InvocationTargetException

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);
    }
}
Also used : JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) UmbrellaException(com.google.web.bindery.event.shared.UmbrellaException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 73 with InvocationTargetException

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;
}
Also used : Constructor(java.lang.reflect.Constructor) AccessibleObject(java.lang.reflect.AccessibleObject) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 74 with InvocationTargetException

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);
}
Also used : TException(org.apache.thrift.TException) Method(java.lang.reflect.Method) IOException(java.io.IOException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) AbstractInvocationHandler(com.google.common.reflect.AbstractInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AbstractInvocationHandler(com.google.common.reflect.AbstractInvocationHandler)

Example 75 with InvocationTargetException

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);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)4781 Method (java.lang.reflect.Method)2031 IOException (java.io.IOException)550 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)492 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)407 ArrayList (java.util.ArrayList)402 List (java.util.List)248 CoreException (org.eclipse.core.runtime.CoreException)247 File (java.io.File)238 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)236 Constructor (java.lang.reflect.Constructor)233 Field (java.lang.reflect.Field)220 Test (org.junit.Test)209 Map (java.util.Map)205 HashMap (java.util.HashMap)202 DBException (org.jkiss.dbeaver.DBException)169 IStatus (org.eclipse.core.runtime.IStatus)136 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)97 Arrays (java.util.Arrays)96 Status (org.eclipse.core.runtime.Status)94