Consistent wrapping of BeanCreationExceptions from instance suppliers

Includes tests for circular references and bean definition overrides.

Closes gh-36725
See gh-36648
This commit is contained in:
Juergen Hoeller
2026-04-30 14:19:25 +02:00
parent cd5fee5347
commit 08c5280843
4 changed files with 115 additions and 5 deletions
@@ -606,9 +606,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
if (ex instanceof BeanCreationException bce && beanName.equals(bce.getBeanName())) {
throw bce;
}
else {
throw new BeanCreationException(mbd.getResourceDescription(), beanName, ex.getMessage(), ex);
}
throw new BeanCreationException(mbd.getResourceDescription(), beanName, ex.getMessage(), ex);
}
if (earlySingletonExposure) {
@@ -1246,8 +1244,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
instance = obtainInstanceFromSupplier(supplier, beanName, mbd);
}
catch (Throwable ex) {
if (ex instanceof BeansException beansException) {
throw beansException;
if (ex instanceof BeanCreationException bce && beanName.equals(bce.getBeanName())) {
throw bce;
}
throw new BeanCreationException(beanName, "Instantiation of supplied bean failed", ex);
}