public Method[] getMethods(Class<? extends Annotation> annotation) { return SecurityActions.getMethodsWithAnnotation(testClass, annotation).toArray(new Method[0]); } }
static Class<?> loadClass(String className) { try { return Class.forName(className, true, getThreadContextClassLoader()); } catch (ClassNotFoundException e) { try { return Class.forName(className, true, SecurityActions.class.getClassLoader()); } catch (ClassNotFoundException e2) { throw new RuntimeException("Could not load class " + className, e2); } } }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType) { @SuppressWarnings("unchecked") Class<T> implClass = (Class<T>) loadClass(className); if (!expectedType.isAssignableFrom(implClass)) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType); } return newInstance(implClass, argumentTypes, arguments); }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(className); out.writeObject(message); out.writeObject(trace); out.writeObject(causeProxy); byte[] originalBytes = new byte[0]; if (original != null) { try { // reset the cause, so we can serialize the exception chain individual SecurityActions.setFieldValue(Throwable.class, original, "cause", null); } catch (Exception e) { // move on, try to serialize anyway } try { ByteArrayOutputStream originalOut = new ByteArrayOutputStream(); ObjectOutputStream output = new ObjectOutputStream(originalOut); output.writeObject(original); output.flush(); originalBytes = originalOut.toByteArray(); } catch (NotSerializableException e) { // in case some class breaks Serialization contract serializationProcessException = e; } } out.writeObject(originalBytes); out.writeObject(serializationProcessException); }
static boolean isClassPresent(String name) { try { loadClass(name); return true; } catch (Exception e) { return false; } }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType, ClassLoader classLoader) { Class<?> clazz = null; try { clazz = Class.forName(className, false, classLoader); } catch (Exception e) { throw new RuntimeException("Could not load class " + className, e); } Object obj = newInstance(clazz, argumentTypes, arguments); try { return expectedType.cast(obj); } catch (Exception e) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType, e); } }
Constructor<T> constructor = getConstructor(implClass, argumentTypes); if (!constructor.isAccessible()) { constructor.setAccessible(true);
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(className); out.writeObject(message); out.writeObject(trace); out.writeObject(causeProxy); byte[] originalBytes = new byte[0]; if (original != null) { try { // reset the cause, so we can serialize the exception chain individual SecurityActions.setFieldValue(Throwable.class, original, "cause", null); } catch (Exception e) { // move on, try to serialize anyway } try { ByteArrayOutputStream originalOut = new ByteArrayOutputStream(); ObjectOutputStream output = new ObjectOutputStream(originalOut); output.writeObject(original); output.flush(); originalBytes = originalOut.toByteArray(); } catch (NotSerializableException e) { // in case some class breaks Serialization contract serializationProcessException = e; } } out.writeObject(originalBytes); out.writeObject(serializationProcessException); }
static boolean isClassPresent(String name) { try { loadClass(name); return true; } catch (Exception e) { return false; } }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType, ClassLoader classLoader) { Class<?> clazz = null; try { clazz = Class.forName(className, false, classLoader); } catch (Exception e) { throw new RuntimeException("Could not load class " + className, e); } Object obj = newInstance(clazz, argumentTypes, arguments); try { return expectedType.cast(obj); } catch (Exception e) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType, e); } }
Constructor<T> constructor = getConstructor(implClass, argumentTypes); if (!constructor.isAccessible()) { constructor.setAccessible(true);
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType) { @SuppressWarnings("unchecked") Class<T> implClass = (Class<T>) loadClass(className); if (!expectedType.isAssignableFrom(implClass)) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType); } return newInstance(implClass, argumentTypes, arguments); }
SecurityActions.setFieldValue(InvocationTargetException.class, original, "target", cause); } else { SecurityActions.setFieldValue(Throwable.class, original, "cause", cause);
static Class<?> loadClass(String className) { try { return Class.forName(className, true, getThreadContextClassLoader()); } catch (ClassNotFoundException e) { try { return Class.forName(className, true, SecurityActions.class.getClassLoader()); } catch (ClassNotFoundException e2) { throw new RuntimeException("Could not load class " + className, e2); } } }
public Method[] getMethods(Class<? extends Annotation> annotation) { return SecurityActions.getMethodsWithAnnotation(testClass, annotation).toArray(new Method[0]); } }
public static TestRunnerAdaptor build() { if (testAdaptor != null) { return testAdaptor; } ManagerBuilder builder = ManagerBuilder.from() .extension(SecurityActions.loadClass(DEFAULT_EXTENSION_CLASS)); return SecurityActions.newInstance( TEST_RUNNER_IMPL_CLASS, new Class<?>[] {ManagerBuilder.class}, new Object[] {builder}, TestRunnerAdaptor.class); } }
SecurityActions.setFieldValue(InvocationTargetException.class, original, "target", cause); } else { SecurityActions.setFieldValue(Throwable.class, original, "cause", cause);
public static TestRunnerAdaptor build() { if (testAdaptor != null) { return testAdaptor; } ManagerBuilder builder = ManagerBuilder.from() .extension(SecurityActions.loadClass(DEFAULT_EXTENSION_CLASS)); return SecurityActions.newInstance( TEST_RUNNER_IMPL_CLASS, new Class<?>[] {ManagerBuilder.class}, new Object[] {builder}, TestRunnerAdaptor.class); } }