/** * Throw a {@link RuntimeException} with given message and cause lifted from an {@link * InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a * cause, neither will the {@link RuntimeException}. */ private static void throwRuntimeException(String msg, InvocationTargetException e) { Throwable cause = e.getCause(); if (cause != null) { throw new RuntimeException(msg + ": " + cause.getMessage(), cause); } else { throw new RuntimeException(msg + ": " + e.getMessage(), e); } }
@SuppressWarnings({"unchecked", "SuspiciousToArrayCall"}) // Reflection on List<Certificate>. @Override public List<Certificate> clean(List<Certificate> chain, String hostname) throws SSLPeerUnverifiedException { try { X509Certificate[] certificates = chain.toArray(new X509Certificate[chain.size()]); return (List<Certificate>) checkServerTrusted.invoke( x509TrustManagerExtensions, certificates, "RSA", hostname); } catch (InvocationTargetException e) { SSLPeerUnverifiedException exception = new SSLPeerUnverifiedException(e.getMessage()); exception.initCause(e); throw exception; } catch (IllegalAccessException e) { throw new AssertionError(e); } }
throw new RuntimeException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new RuntimeException(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new RuntimeException(e.getMessage(), e);
private XPathEvaluator createEvaluator(String xpath2) { try { return (XPathEvaluator)EVALUATOR_CONSTRUCTOR.newInstance(new Object[] {xpath, builder}); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException)cause; } throw new RuntimeException("Invalid XPath Expression: " + xpath + " reason: " + e.getMessage(), e); } catch (Throwable e) { throw new RuntimeException("Invalid XPath Expression: " + xpath + " reason: " + e.getMessage(), e); } }
public Class[] getClassArrayValue(Annotation a, String name) { try { return (Class[])a.annotationType().getMethod(name).invoke(a); } catch (IllegalAccessException e) { // impossible throw new IllegalAccessError(e.getMessage()); } catch (InvocationTargetException e) { // impossible throw new InternalError(e.getMessage()); } catch (NoSuchMethodException e) { throw new NoSuchMethodError(e.getMessage()); } }
@SuppressWarnings({"unchecked", "SuspiciousToArrayCall"}) // Reflection on List<Certificate>. @Override public List<Certificate> clean(List<Certificate> chain, String hostname) throws SSLPeerUnverifiedException { try { X509Certificate[] certificates = chain.toArray(new X509Certificate[chain.size()]); return (List<Certificate>) checkServerTrusted.invoke( x509TrustManagerExtensions, certificates, "RSA", hostname); } catch (InvocationTargetException e) { SSLPeerUnverifiedException exception = new SSLPeerUnverifiedException(e.getMessage()); exception.initCause(e); throw exception; } catch (IllegalAccessException e) { throw new AssertionError(e); } }
public Class getClassValue(Annotation a, String name) { try { return (Class)a.annotationType().getMethod(name).invoke(a); } catch (IllegalAccessException e) { // impossible throw new IllegalAccessError(e.getMessage()); } catch (InvocationTargetException e) { // impossible throw new InternalError(Messages.CLASS_NOT_FOUND.format(a.annotationType(), e.getMessage())); } catch (NoSuchMethodException e) { throw new NoSuchMethodError(e.getMessage()); } }
private static Long callLongMethod(Class<?> clazz, String methodName) { Method method; // ///CLOVER:OFF try { method = ObjectStreamClass.class.getDeclaredMethod(methodName, Class.class); } catch (NoSuchMethodException e) { throw new InternalError("ObjectStreamClass." + methodName + " seems to have vanished"); } boolean accessible = method.isAccessible(); method.setAccessible(true); Long suid; try { suid = (Long) method.invoke(null, clazz); } catch (IllegalAccessException e) { throw new InternalError("ObjectStreamClass." + methodName + " should have been accessible"); } catch (InvocationTargetException e) { throw new InternalError("ObjectStreamClass." + methodName + " failed to be called: " + e.getMessage()); } method.setAccessible(accessible); // ///CLOVER:ON return suid; }
private static Object instantiate(Class<?> cl) throws Exception { Constructor<?>[] constructors = cl.getDeclaredConstructors(); Constructor<?> constructor = null; int argc = Integer.MAX_VALUE; for (Constructor<?> c : constructors) { if (c.getParameterTypes().length < argc) { argc = c.getParameterTypes().length; constructor = c; } } if (constructor != null) { Class<?>[] paramTypes = constructor.getParameterTypes(); Object[] constructorArgs = new Object[paramTypes.length]; for (int i = 0; i < constructorArgs.length; i++) { constructorArgs[i] = getConstructorArg(paramTypes[i]); } try { constructor.setAccessible(true); return constructor.newInstance(constructorArgs); } catch (InstantiationException e) { LogHelper.warn(logger, e.getMessage(), e); } catch (IllegalAccessException e) { LogHelper.warn(logger, e.getMessage(), e); } catch (InvocationTargetException e) { LogHelper.warn(logger, e.getMessage(), e); } } return cl.newInstance(); }
private static Object instantiate(Class<?> cl) throws Exception { Constructor<?>[] constructors = cl.getDeclaredConstructors(); Constructor<?> constructor = null; int argc = Integer.MAX_VALUE; for (Constructor<?> c : constructors) { if (c.getParameterTypes().length < argc) { argc = c.getParameterTypes().length; constructor = c; } } if (constructor != null) { Class<?>[] paramTypes = constructor.getParameterTypes(); Object[] constructorArgs = new Object[paramTypes.length]; for (int i = 0; i < constructorArgs.length; i++) { constructorArgs[i] = getConstructorArg(paramTypes[i]); } try { constructor.setAccessible(true); return constructor.newInstance(constructorArgs); } catch (InstantiationException e) { LogHelper.warn(logger, e.getMessage(), e); } catch (IllegalAccessException e) { LogHelper.warn(logger, e.getMessage(), e); } catch (InvocationTargetException e) { LogHelper.warn(logger, e.getMessage(), e); } } return cl.newInstance(); }
@Override public void setValue(Object pojo, Object value) throws IllegalArgumentException { try { _method.invoke(pojo, value); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Failed to setValue() with method " +getFullName()+": "+e.getMessage(), e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("Failed to setValue() with method " +getFullName()+": "+e.getMessage(), e); } }
@SuppressWarnings({"unchecked", "SuspiciousToArrayCall"}) // Reflection on List<Certificate>. @Override public List<Certificate> clean(List<Certificate> chain, String hostname) throws SSLPeerUnverifiedException { try { X509Certificate[] certificates = chain.toArray(new X509Certificate[chain.size()]); return (List<Certificate>) checkServerTrusted.invoke( x509TrustManagerExtensions, certificates, "RSA", hostname); } catch (InvocationTargetException e) { SSLPeerUnverifiedException exception = new SSLPeerUnverifiedException(e.getMessage()); exception.initCause(e); throw exception; } catch (IllegalAccessException e) { throw new AssertionError(e); } }
@SuppressWarnings("unchecked") @Override public R visitUnknown(TypeMirror t, P p) { if (intersectionTypeClass != null && intersectionTypeClass.isInstance(t)) { try { List<TypeMirror> bounds = (List<TypeMirror>) getBoundsMethod.invoke(t); return bounds.get(0).accept(this, p); } catch (IllegalAccessException e) { throw new RuntimeException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new RuntimeException(e.getMessage(), e); } } else { return super.visitUnknown(t, p); } }
boolean invoke(Object receiver, String methodName, String argument) { try { Method method = receiver.getClass().getMethod(methodName, mArgType); method.invoke(receiver, convertArgument(argument)); return true; } catch (NoSuchMethodException ignored) { // ignore } catch (InvocationTargetException e) { LogUtil.w("InvocationTargetException: " + e.getMessage()); } catch (IllegalAccessException e) { LogUtil.w("IllegalAccessException: " + e.getMessage()); } catch (IllegalArgumentException e) { LogUtil.w("IllegalArgumentException: " + e.getMessage()); } return false; }
@Override @SuppressWarnings("unchecked") public T newInstance(Object... args) { try { for (Function<Object[], Object[]> transformer : transformers) { args = transformer.apply(args); } return (T) constructor.newInstance(args); } catch (SecurityException e) { throw new ExpressionException(e.getMessage(), e); } catch (InstantiationException e) { throw new ExpressionException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new ExpressionException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new ExpressionException(e.getMessage(), e); } }
@Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { Type returnType = method.getGenericReturnType(); assertTrue("Jaxb2Marshaller does not support JAXBElement<" + method.getName().substring(9) + ">", marshaller.supports(returnType)); try { // make sure the marshalling does not result in errors Object returnValue = method.invoke(primitives); marshaller.marshal(returnValue, new StreamResult(new ByteArrayOutputStream())); } catch (InvocationTargetException e) { fail(e.getMessage()); } } }, new ReflectionUtils.MethodFilter() {
@Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { Type returnType = method.getGenericReturnType(); assertTrue("Jaxb2Marshaller does not support JAXBElement<" + method.getName().substring(13) + ">", marshaller.supports(returnType)); try { // make sure the marshalling does not result in errors Object returnValue = method.invoke(standardClasses); marshaller.marshal(returnValue, new StreamResult(new ByteArrayOutputStream())); } catch (InvocationTargetException e) { fail(e.getMessage()); } } }, new ReflectionUtils.MethodFilter() {
throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (InvocationTargetException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (InvocationTargetException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);