Description
When registering two singleton beans using SingletonBeanRegistry#registerSingleton and using @ConditionalOnSingleCandidate(TestBean.class) a NullPointerException occurs due to the absence of corresponding bean definitions.
Reproduction Steps
Register singleton bean using SingletonBeanRegistry#registerSingleton:
beanFactory.registerSingleton("bean1", new TestBean());
beanFactory.registerSingleton("bean2", new TestBean());
Use @ConditionalOnSingleCandidate(TestBean.class):
@Configuration
@ConditionalOnSingleCandidate(TestBean.class)
public class TestConfiguration {
@Bean
public SomeBean someBean() {
return new SomeBean();
}
}
The application will throw a NullPointerException during startup.
Environment Information
- Spring Boot Version: 3.5.7
- JDK Version: 21