Skip to content

Commit c1569d7

Browse files
committed
Handle NoClassDefFoundError consistently for TELs
Prior to this commit, a NoClassDefFoundError caught in TestContextManager's retrieveTestExecutionListeners() method would be handled differently for implicit default listeners (i.e., listeners not declared via @TestExecutionListeners) and listeners explicitly declared via @TestExecutionListeners. Specifically, a NoClassDefFoundError would cause a test to fail for an explicitly declared TestExecutionListener but not for an implicitly declared one. This commit addresses this issue by: - Always swallowing a NoClassDefFoundError for both implicitly and explicitly declared TestExecutionListeners. - Changing the log level from DEBUG to INFO to make such situations more visible to the average end user. Issue: SPR-11347 Backport-Commit: fb12e23
1 parent fdd31c0 commit c1569d7

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

spring-test/src/main/java/org/springframework/test/context/TestContextManager.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,13 @@ private TestExecutionListener[] retrieveTestExecutionListeners(Class<?> clazz) {
176176
Class<TestExecutionListeners> annotationType = TestExecutionListeners.class;
177177
List<Class<? extends TestExecutionListener>> classesList = new ArrayList<Class<? extends TestExecutionListener>>();
178178
Class<?> declaringClass = AnnotationUtils.findAnnotationDeclaringClass(annotationType, clazz);
179-
boolean defaultListeners = false;
180179

181180
// Use defaults?
182181
if (declaringClass == null) {
183182
if (logger.isDebugEnabled()) {
184183
logger.debug("@TestExecutionListeners is not present for class [" + clazz + "]: using defaults.");
185184
}
186185
classesList.addAll(getDefaultTestExecutionListenerClasses());
187-
defaultListeners = true;
188186
} else {
189187
// Traverse the class hierarchy...
190188
while (declaringClass != null) {
@@ -220,15 +218,12 @@ private TestExecutionListener[] retrieveTestExecutionListeners(Class<?> clazz) {
220218
for (Class<? extends TestExecutionListener> listenerClass : classesList) {
221219
try {
222220
listeners.add(BeanUtils.instantiateClass(listenerClass));
223-
} catch (NoClassDefFoundError err) {
224-
if (defaultListeners) {
225-
if (logger.isDebugEnabled()) {
226-
logger.debug("Could not instantiate default TestExecutionListener class ["
227-
+ listenerClass.getName()
228-
+ "]. Specify custom listener classes or make the default listener classes available.");
229-
}
230-
} else {
231-
throw err;
221+
}
222+
catch (NoClassDefFoundError err) {
223+
if (logger.isInfoEnabled()) {
224+
logger.info(String.format("Could not instantiate TestExecutionListener class [%s]. "
225+
+ "Specify custom listener classes or make the default listener classes "
226+
+ "(and their dependencies) available.", listenerClass.getName()));
232227
}
233228
}
234229
}

0 commit comments

Comments
 (0)