Skip initialization of a NullBean

Prior to this commit, AbstractAutowireCapableBeanFactory's
initializeBean() method always attempted to initialize a NullBean.

However, invokeInitMethods() (which is invoked by initializeBean())
skips processing of a NullBean, which is logical since a NullBean will
never contain init-methods.

In practice, initialization and post-processing of a NullBean should
not result in any change to the NullBean.

This commit therefore skips initialization of a NullBean altogether.

Closes gh-35165
This commit is contained in:
Sam Brannen
2025-07-07 11:12:28 +02:00
parent 1982c7e020
commit a80305ee71
@@ -1798,6 +1798,11 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
*/
@SuppressWarnings("deprecation")
protected Object initializeBean(String beanName, Object bean, @Nullable RootBeanDefinition mbd) {
// Skip initialization of a NullBean
if (bean.getClass() == NullBean.class) {
return bean;
}
invokeAwareMethods(beanName, bean);
Object wrappedBean = bean;