General defensiveness about the bootstrap ClassLoader (i.e. null ClassLoader)
Issue: SPR-11721
This commit is contained in:
@@ -26,11 +26,13 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.test.context.MetaAnnotationUtils.AnnotationDescriptor;
|
||||
import org.springframework.test.context.MetaAnnotationUtils.*;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.springframework.test.context.MetaAnnotationUtils.*;
|
||||
@@ -159,8 +161,7 @@ public class TestContextManager {
|
||||
* registered for this {@code TestContextManager} in reverse order.
|
||||
*/
|
||||
private List<TestExecutionListener> getReversedTestExecutionListeners() {
|
||||
List<TestExecutionListener> listenersReversed = new ArrayList<TestExecutionListener>(
|
||||
getTestExecutionListeners());
|
||||
List<TestExecutionListener> listenersReversed = new ArrayList<TestExecutionListener>(getTestExecutionListeners());
|
||||
Collections.reverse(listenersReversed);
|
||||
return listenersReversed;
|
||||
}
|
||||
@@ -234,9 +235,9 @@ public class TestContextManager {
|
||||
}
|
||||
catch (NoClassDefFoundError err) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(String.format("Could not instantiate TestExecutionListener class [%s]. "
|
||||
+ "Specify custom listener classes or make the default listener classes "
|
||||
+ "(and their dependencies) available.", listenerClass.getName()));
|
||||
logger.info(String.format("Could not instantiate TestExecutionListener class [%s]. " +
|
||||
"Specify custom listener classes or make the default listener classes " +
|
||||
"(and their dependencies) available.", listenerClass.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -252,15 +253,15 @@ public class TestContextManager {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() {
|
||||
Set<Class<? extends TestExecutionListener>> defaultListenerClasses = new LinkedHashSet<Class<? extends TestExecutionListener>>();
|
||||
ClassLoader cl = getClass().getClassLoader();
|
||||
for (String className : DEFAULT_TEST_EXECUTION_LISTENER_CLASS_NAMES) {
|
||||
try {
|
||||
defaultListenerClasses.add((Class<? extends TestExecutionListener>) getClass().getClassLoader().loadClass(
|
||||
className));
|
||||
defaultListenerClasses.add((Class<? extends TestExecutionListener>) ClassUtils.forName(className, cl));
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not load default TestExecutionListener class [" + className
|
||||
+ "]. Specify custom listener classes or make the default listener classes available.", t);
|
||||
logger.debug("Could not load default TestExecutionListener class [" + className +
|
||||
"]. Specify custom listener classes or make the default listener classes available.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,7 +282,7 @@ public class TestContextManager {
|
||||
* @see #getTestExecutionListeners()
|
||||
*/
|
||||
public void beforeTestClass() throws Exception {
|
||||
final Class<?> testClass = getTestContext().getTestClass();
|
||||
Class<?> testClass = getTestContext().getTestClass();
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("beforeTestClass(): class [" + testClass + "]");
|
||||
}
|
||||
@@ -292,8 +293,8 @@ public class TestContextManager {
|
||||
testExecutionListener.beforeTestClass(getTestContext());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener
|
||||
+ "] to process 'before class' callback for test class [" + testClass + "]", ex);
|
||||
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener +
|
||||
"] to process 'before class' callback for test class [" + testClass + "]", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
@@ -325,8 +326,8 @@ public class TestContextManager {
|
||||
testExecutionListener.prepareTestInstance(getTestContext());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error("Caught exception while allowing TestExecutionListener [" + testExecutionListener
|
||||
+ "] to prepare test instance [" + testInstance + "]", ex);
|
||||
logger.error("Caught exception while allowing TestExecutionListener [" + testExecutionListener +
|
||||
"] to prepare test instance [" + testInstance + "]", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
@@ -362,9 +363,9 @@ public class TestContextManager {
|
||||
testExecutionListener.beforeTestMethod(getTestContext());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener
|
||||
+ "] to process 'before' execution of test method [" + testMethod + "] for test instance ["
|
||||
+ testInstance + "]", ex);
|
||||
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener +
|
||||
"] to process 'before' execution of test method [" + testMethod + "] for test instance [" +
|
||||
testInstance + "]", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
@@ -410,9 +411,9 @@ public class TestContextManager {
|
||||
testExecutionListener.afterTestMethod(getTestContext());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener
|
||||
+ "] to process 'after' execution for test: method [" + testMethod + "], instance ["
|
||||
+ testInstance + "], exception [" + exception + "]", ex);
|
||||
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener +
|
||||
"] to process 'after' execution for test: method [" + testMethod + "], instance [" +
|
||||
testInstance + "], exception [" + exception + "]", ex);
|
||||
if (afterTestMethodException == null) {
|
||||
afterTestMethodException = ex;
|
||||
}
|
||||
@@ -438,7 +439,7 @@ public class TestContextManager {
|
||||
* @see #getTestExecutionListeners()
|
||||
*/
|
||||
public void afterTestClass() throws Exception {
|
||||
final Class<?> testClass = getTestContext().getTestClass();
|
||||
Class<?> testClass = getTestContext().getTestClass();
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("afterTestClass(): class [" + testClass + "]");
|
||||
}
|
||||
@@ -452,8 +453,8 @@ public class TestContextManager {
|
||||
testExecutionListener.afterTestClass(getTestContext());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener
|
||||
+ "] to process 'after class' callback for test class [" + testClass + "]", ex);
|
||||
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener +
|
||||
"] to process 'after class' callback for test class [" + testClass + "]", ex);
|
||||
if (afterTestClassException == null) {
|
||||
afterTestClassException = ex;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user