Replace deep exception message nesting with custom inclusion of cause messages
Includes deprecation of NestedServletException, whereas NestedCheckedException and NestedRuntimeException remain as base classes with several convenience methods. Closes gh-25162
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -71,7 +71,8 @@ public class TypeMismatchException extends PropertyAccessException {
|
||||
(requiredType != null ?
|
||||
" to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : "") +
|
||||
(propertyChangeEvent.getPropertyName() != null ?
|
||||
" for property '" + propertyChangeEvent.getPropertyName() + "'" : ""),
|
||||
" for property '" + propertyChangeEvent.getPropertyName() + "'" : "") +
|
||||
(cause != null ? "; " + cause.getMessage() : ""),
|
||||
cause);
|
||||
this.propertyName = propertyChangeEvent.getPropertyName();
|
||||
this.value = propertyChangeEvent.getNewValue();
|
||||
@@ -97,7 +98,8 @@ public class TypeMismatchException extends PropertyAccessException {
|
||||
*/
|
||||
public TypeMismatchException(@Nullable Object value, @Nullable Class<?> requiredType, @Nullable Throwable cause) {
|
||||
super("Failed to convert value of type '" + ClassUtils.getDescriptiveType(value) + "'" +
|
||||
(requiredType != null ? " to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : ""),
|
||||
(requiredType != null ? " to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : "") +
|
||||
(cause != null ? "; " + cause.getMessage() : ""),
|
||||
cause);
|
||||
this.value = value;
|
||||
this.requiredType = requiredType;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,7 +62,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException {
|
||||
public UnsatisfiedDependencyException(
|
||||
@Nullable String resourceDescription, @Nullable String beanName, String propertyName, BeansException ex) {
|
||||
|
||||
this(resourceDescription, beanName, propertyName, "");
|
||||
this(resourceDescription, beanName, propertyName, ex.getMessage());
|
||||
initCause(ex);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException {
|
||||
public UnsatisfiedDependencyException(
|
||||
@Nullable String resourceDescription, @Nullable String beanName, @Nullable InjectionPoint injectionPoint, BeansException ex) {
|
||||
|
||||
this(resourceDescription, beanName, injectionPoint, "");
|
||||
this(resourceDescription, beanName, injectionPoint, ex.getMessage());
|
||||
initCause(ex);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -86,7 +86,7 @@ public abstract class PropertyResourceConfigurer extends PropertiesLoaderSupport
|
||||
processProperties(beanFactory, mergedProps);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new BeanInitializationException("Could not load properties", ex);
|
||||
throw new BeanInitializationException("Could not load properties: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -608,8 +608,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
throw (BeanCreationException) ex;
|
||||
}
|
||||
else {
|
||||
throw new BeanCreationException(
|
||||
mbd.getResourceDescription(), beanName, "Initialization of bean failed", ex);
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1302,8 +1301,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
return bw;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new BeanCreationException(
|
||||
mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex);
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1699,8 +1697,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
bw.setPropertyValues(new MutablePropertyValues(deepCopy));
|
||||
}
|
||||
catch (BeansException ex) {
|
||||
throw new BeanCreationException(
|
||||
mbd.getResourceDescription(), beanName, "Error setting property values", ex);
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1752,8 +1749,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new BeanCreationException(
|
||||
(mbd != null ? mbd.getResourceDescription() : null),
|
||||
beanName, "Invocation of init method failed", ex);
|
||||
(mbd != null ? mbd.getResourceDescription() : null), beanName, ex.getMessage(), ex);
|
||||
}
|
||||
if (mbd == null || !mbd.isSynthetic()) {
|
||||
wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
|
||||
|
||||
@@ -303,8 +303,7 @@ class ConstructorResolver {
|
||||
return strategy.instantiate(mbd, beanName, this.beanFactory, constructorToUse, argsToUse);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"Bean instantiation via constructor failed", ex);
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,8 +630,7 @@ class ConstructorResolver {
|
||||
mbd, beanName, this.beanFactory, factoryBean, factoryMethod, args);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"Bean instantiation via factory method failed", ex);
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -152,7 +152,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
|
||||
"Cannot access factory method '" + factoryMethod.getName() + "'; is it public?", ex);
|
||||
}
|
||||
catch (InvocationTargetException ex) {
|
||||
String msg = "Factory method '" + factoryMethod.getName() + "' threw exception";
|
||||
String msg = ex.getTargetException().getMessage();
|
||||
if (bd.getFactoryBeanName() != null && owner instanceof ConfigurableBeanFactory &&
|
||||
((ConfigurableBeanFactory) owner).isCurrentlyInCreation(bd.getFactoryBeanName())) {
|
||||
msg = "Circular reference involving containing bean '" + bd.getFactoryBeanName() + "' - consider " +
|
||||
|
||||
Reference in New Issue
Block a user