public Object invoke(final Object o, final Method method, final Object[] objects) throws Throwable { ClassLoaderStack.push(serviceClassLoader); try { return method.invoke(service, objects); } catch (final InvocationTargetException e) { throw e.getTargetException(); } finally { ClassLoaderStack.pop(); } } }
/** * Executes the provided {@link Callable} implementation in the specified {@link ClassLoader}. * <p> * Utilises the {@link com.atlassian.plugin.util.ClassLoaderStack#push} method to save the old {@link ClassLoader} and * set the one specified as <code>newClassLoader</code>. {@link com.atlassian.plugin.util.ClassLoaderStack#pop} is * called in a finally block to ensure the {@link ClassLoader} is set back to the original one. * * @param newClassLoader The {@link ClassLoader} to run the specified {@link Runnable} in. * @param callable The implementation to be run in the specified {@link ClassLoader} * @return the result of the {@link Callable} * @since 2.7.0 */ public static <T> T runInContext(ClassLoader newClassLoader, Callable<T> callable) throws Exception { ClassLoaderStack.push(newClassLoader); try { return callable.call(); } finally { ClassLoaderStack.pop(); } } }