With https://github.com/spring-projects/spring-framework/issues/26241 we should update @ConditionalOnSingleCandidate to work when there is a single regular bean and a fallback bean.

Comment From: linw-bai

Description

When registering two singleton beans using org.springframework.beans.factory.config.SingletonBeanRegistry#registerSingleton, and use @ConditionalOnSingleCandidate(TestBean.class) a NullPointerException occurs due to the absence of corresponding bean definitions.

Reproduction Steps

Register singleton bean using SingletonBeanRegistry#registerSingleton: ```java beanFactory.registerSingleton("bean1", new TestBean()); beanFactory.registerSingleton("bean2", new TestBean());


use @ConditionalOnSingleCandidate(TestBean.class)
```java
@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

Comment From: philwebb

@linw-bai Could you please open a new issue for this and provide a sample along with the complete stacktrace so we can diagnose things.