From a80305ee7125d701229b2abce4180cba66b879e1 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 7 Jul 2025 11:12:16 +0200 Subject: [PATCH] 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 --- .../factory/support/AbstractAutowireCapableBeanFactory.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index cf902e16331..20510109a40 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -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;