Skip to content

Commit 91a8993

Browse files
committed
Skip init/destroy method check for null beans
Issue: SPR-16063
1 parent d611486 commit 91a8993

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ protected void invokeInitMethods(String beanName, final Object bean, @Nullable R
17641764
}
17651765
}
17661766

1767-
if (mbd != null) {
1767+
if (mbd != null && bean.getClass() != NullBean.class) {
17681768
String initMethodName = mbd.getInitMethodName();
17691769
if (StringUtils.hasLength(initMethodName) &&
17701770
!(isInitializingBean && "afterPropertiesSet".equals(initMethodName)) &&

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,8 +1662,8 @@ public boolean isBeanNameInUse(String beanName) {
16621662
* @see AbstractBeanDefinition#getDestroyMethodName()
16631663
* @see org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
16641664
*/
1665-
protected boolean requiresDestruction(@Nullable Object bean, RootBeanDefinition mbd) {
1666-
return (bean != null &&
1665+
protected boolean requiresDestruction(Object bean, RootBeanDefinition mbd) {
1666+
return (bean.getClass() != NullBean.class &&
16671667
(DisposableBeanAdapter.hasDestroyMethod(bean, mbd) || (hasDestructionAwareBeanPostProcessors() &&
16681668
DisposableBeanAdapter.hasApplicableProcessors(bean, getBeanPostProcessors()))));
16691669
}

spring-beans/src/test/resources/org/springframework/beans/factory/xml/factory-methods.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</bean>
2828

2929
<bean id="null" class="org.springframework.beans.factory.xml.FactoryMethods"
30-
factory-method="nullInstance"/>
30+
factory-method="nullInstance" init-method="getName"/>
3131

3232
<bean id="nullWithProperty" class="org.springframework.beans.factory.xml.FactoryMethods"
3333
factory-method="nullInstance" init-method="getName" scope="prototype">

0 commit comments

Comments
 (0)