-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Chris Beams opened SPR-7523 and commented
To reproduce:
@Test
public void nullBeanRegistration() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton("nullBean", null);
new GenericApplicationContext(bf).refresh();
}
Notice the BeanNotFoundException
upon refresh()
.
This is happening because DefaultSingletonBeanRegistry.getSingleton()
returns literal null
, and AbstractBeanFactory.isFactoryBean()
interprets null
as meaning "No singleton instance found".
Resolution:
In isFactoryBean()
, if the call to getSingleton()
returns null, need need to double check whether the bean name is listed in getSingletonNames()
. Just evaluating whether it's null is not enough information upon which to make the subsequent decisions.
Those 'subsequent decisions' include assuming that the bean name in question ('nullBean') must be associated with a BeanDefinition
, and thus we get the BNFE mentioned above.
Referenced from: commits 05a3f3a