Handle missing dependencies for optional TestExecutionListener again
Commitd1b65f6d3eintroduced a regression regarding the handling of missing dependencies for optional (typically default) TestExecutionListeners. Prior tod1b65f6d3ea TestExecutionListener was instantiated using java.lang.Class.newInstance() which never throws an InvocationTargetException. With the switch to the new SpringFactoriesLoader APIs, a TestExecutionListener is now instantiated using java.lang.reflect.Constructor.newInstance(Object...) which can throw an InvocationTargetException. This commit addresses the regression by unwrapping the target exception in an InvocationTargetException. See gh-28666 Closes gh-28828
This commit is contained in:
parent
9962aa00a0
commit
f5503298fb
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.test.context.support;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
|
@ -200,7 +201,9 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
|
|||
* @see SpringFactoriesLoader#load(Class, FailureHandler)
|
||||
*/
|
||||
protected List<TestExecutionListener> getDefaultTestExecutionListeners() {
|
||||
FailureHandler failureHandler = (factoryType, factoryImplementationName, ex) -> {
|
||||
FailureHandler failureHandler = (factoryType, factoryImplementationName, failure) -> {
|
||||
Throwable ex = (failure instanceof InvocationTargetException ite ?
|
||||
ite.getTargetException() : failure);
|
||||
if (ex instanceof LinkageError || ex instanceof ClassNotFoundException) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not load default TestExecutionListener [" + factoryImplementationName +
|
||||
|
|
|
|||
Loading…
Reference in New Issue