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;
}
}
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();
}
}
}
}
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;
}
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);
}
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;
}
Aggregations