Browse Source

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
pull/34878/merge
Sam Brannen 7 months ago
parent
commit
a80305ee71
  1. 5
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

5
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

@ -1798,6 +1798,11 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac @@ -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;

Loading…
Cancel
Save