Search in sources :

Example 66 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project android_frameworks_base by ParanoidAndroid.

the class BandwidthTestCase method runMethod.

private void runMethod(Method runMethod, int tolerance, boolean isRepetitive) throws Throwable {
    //This is a copy of {@link InstrumentationTestCase#runMethod}
    Throwable exception = null;
    int runCount = 0;
    do {
        try {
            runMethod.invoke(this, (Object[]) null);
            exception = null;
        } catch (InvocationTargetException e) {
            e.fillInStackTrace();
            exception = e.getTargetException();
        } catch (IllegalAccessException e) {
            e.fillInStackTrace();
            exception = e;
        } finally {
            runCount++;
            // Report current iteration number, if test is repetitive
            if (isRepetitive) {
                Bundle iterations = new Bundle();
                iterations.putInt("currentiterations", runCount);
                getInstrumentation().sendStatus(2, iterations);
            }
        }
    } while ((runCount < tolerance) && (isRepetitive || exception != null));
    if (exception != null) {
        throw exception;
    }
}
Also used : Bundle(android.os.Bundle) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 67 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project netty by netty.

the class AbstractTestsuiteTest method run.

protected void run() throws Throwable {
    List<TestsuitePermutation.BootstrapFactory<T>> combos = newFactories();
    for (ByteBufAllocator allocator : newAllocators()) {
        int i = 0;
        for (TestsuitePermutation.BootstrapFactory<T> e : combos) {
            cb = e.newInstance();
            configure(cb, allocator);
            logger.info(String.format("Running: %s %d of %d with %s", testName.getMethodName(), ++i, combos.size(), StringUtil.simpleClassName(allocator)));
            try {
                Method m = getClass().getMethod(TestUtils.testMethodName(testName), clazz);
                m.invoke(this, cb);
            } catch (InvocationTargetException ex) {
                throw ex.getCause();
            }
        }
    }
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 68 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project neo4j by neo4j.

the class HotspotManagementSupport method getJMXServiceURL.

@Override
protected JMXServiceURL getJMXServiceURL(KernelData kernel) {
    JMXServiceURL url = null;
    Log log = kernel.graphDatabase().getDependencyResolver().resolveDependency(LogService.class).getInternalLog(HotspotManagementSupport.class);
    try {
        Class<?> cal = Class.forName("sun.management.ConnectorAddressLink");
        try {
            Method importRemoteFrom = cal.getMethod("importRemoteFrom", int.class);
            @SuppressWarnings("unchecked") Map<String, String> remote = (Map<String, String>) importRemoteFrom.invoke(null, 0);
            url = getUrlFrom(remote);
        } catch (NoSuchMethodException ex) {
        // handled by null check
        }
        if (url == null) {
            Method importFrom = cal.getMethod("importFrom", int.class);
            url = getUrlFrom((String) importFrom.invoke(null, 0));
        }
    } catch (InvocationTargetException e) {
        log.warn("Failed to load local JMX connection URL.", e.getTargetException());
    } catch (LinkageError | Exception e) {
        log.warn("Failed to load local JMX connection URL.", e);
    }
    // No previous connection server -- create one!
    if (url == null) {
        int port = 0;
        try {
            port = kernel.getConfig().get(setting("jmx.port", INTEGER, "0"));
        } catch (NumberFormatException ok) {
        // handled by 0-check
        }
        if (port > 0) {
            boolean useSSL = kernel.getConfig().get(setting("jmx.use_ssl", BOOLEAN, "false"));
            log.debug("Creating new MBean server on port %s%s", port, useSSL ? " using ssl" : "");
            JMXConnectorServer server = createServer(port, useSSL, log);
            if (server != null) {
                try {
                    server.start();
                } catch (IOException e) {
                    log.warn("Failed to start MBean server", e);
                    server = null;
                }
                if (server != null) {
                    try {
                        server.getMBeanServer().registerMBean(server, KernelProxy.createObjectName(kernel.instanceId(), "JMX Server"));
                    } catch (Exception e) {
                        log.warn("Failed to register MBean server as JMX bean", e);
                    }
                    url = server.getAddress();
                }
            }
        }
    }
    return url;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) Log(org.neo4j.logging.Log) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JMXConnectorServer(javax.management.remote.JMXConnectorServer) HashMap(java.util.HashMap) Map(java.util.Map) LogService(org.neo4j.kernel.impl.logging.LogService)

Example 69 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project generator by mybatis.

the class RunGeneratorAction method handleException.

private void handleException(Exception exception, Shell shell) {
    IStatus status;
    Throwable exceptionToHandle;
    if (exception instanceof InvocationTargetException) {
        exceptionToHandle = ((InvocationTargetException) exception).getCause();
    } else {
        exceptionToHandle = exception;
    }
    if (exceptionToHandle instanceof InterruptedException) {
        status = new Status(IStatus.CANCEL, Activator.PLUGIN_ID, IStatus.CANCEL, "Cancelled by User", exceptionToHandle);
    } else if (exceptionToHandle instanceof CoreException) {
        status = ((CoreException) exceptionToHandle).getStatus();
    } else {
        String message = "Unexpected error while running MyBatis Generator.";
        status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, message, exceptionToHandle);
        Activator.getDefault().getLog().log(status);
    }
    ErrorDialog.openError(shell, "MyBatis Generator", "Generation Failed", status, IStatus.ERROR | IStatus.CANCEL);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 70 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hackpad by dropbox.

the class FlexibleCompletor method getStream.

public static InputStream getStream(Scriptable scope) {
    // We don't want a compile-time dependency on the JLine jar, so use
    // reflection to load and reference the JLine classes.
    ClassLoader classLoader = ShellLine.class.getClassLoader();
    if (classLoader == null) {
        // If the attempt to get a class specific class loader above failed
        // then fallback to the system class loader.
        classLoader = ClassLoader.getSystemClassLoader();
    }
    if (classLoader == null) {
        // loader then give up (avoid a NullPointerException).
        return null;
    }
    Class<?> readerClass = Kit.classOrNull(classLoader, "jline.ConsoleReader");
    if (readerClass == null)
        return null;
    try {
        // ConsoleReader reader = new ConsoleReader();
        Constructor<?> c = readerClass.getConstructor();
        Object reader = c.newInstance();
        // reader.setBellEnabled(false);
        Method m = readerClass.getMethod("setBellEnabled", Boolean.TYPE);
        m.invoke(reader, Boolean.FALSE);
        // reader.addCompletor(new FlexibleCompletor(prefixes));
        Class<?> completorClass = Kit.classOrNull(classLoader, "jline.Completor");
        m = readerClass.getMethod("addCompletor", completorClass);
        Object completor = Proxy.newProxyInstance(classLoader, new Class[] { completorClass }, new FlexibleCompletor(completorClass, scope));
        m.invoke(reader, completor);
        // return new ConsoleReaderInputStream(reader);
        Class<?> inputStreamClass = Kit.classOrNull(classLoader, "jline.ConsoleReaderInputStream");
        c = inputStreamClass.getConstructor(readerClass);
        return (InputStream) c.newInstance(reader);
    } catch (NoSuchMethodException e) {
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    }
    return null;
}
Also used : InputStream(java.io.InputStream) ScriptableObject(org.mozilla.javascript.ScriptableObject) 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