From c1569d7ecd19a445b6e0030ec52eac0b6b9c8d14 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 22 Jan 2014 23:28:36 +0100 Subject: [PATCH] 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: fb12e234fcee416c4ea6359a2242ce7e3977b0b6 --- .../test/context/TestContextManager.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java index aabdf33dfb7..d6042edd083 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java @@ -176,7 +176,6 @@ public class TestContextManager { Class annotationType = TestExecutionListeners.class; List> classesList = new ArrayList>(); Class declaringClass = AnnotationUtils.findAnnotationDeclaringClass(annotationType, clazz); - boolean defaultListeners = false; // Use defaults? if (declaringClass == null) { @@ -184,7 +183,6 @@ public class TestContextManager { logger.debug("@TestExecutionListeners is not present for class [" + clazz + "]: using defaults."); } classesList.addAll(getDefaultTestExecutionListenerClasses()); - defaultListeners = true; } else { // Traverse the class hierarchy... while (declaringClass != null) { @@ -220,15 +218,12 @@ public class TestContextManager { for (Class listenerClass : classesList) { try { listeners.add(BeanUtils.instantiateClass(listenerClass)); - } catch (NoClassDefFoundError err) { - if (defaultListeners) { - if (logger.isDebugEnabled()) { - logger.debug("Could not instantiate default TestExecutionListener class [" - + listenerClass.getName() - + "]. Specify custom listener classes or make the default listener classes available."); - } - } else { - throw err; + } + 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())); } } }