Skip to content

DefaultListableBeanFactory::getBeanNamesForType does not always return all bean names #35634

@nevenamanova-afk

Description

@nevenamanova-afk

While trying to upgrade to Spring 6.2.11 from Spring 6.2.10, I came upon an issue where the method DefaultListableBeanFactory::getBeanNamesForType(Class type) does not always return all the bean names for a type and its subtypes. The issue is easily reproducible with the following piece of code:

 try (GenericApplicationContext context = new GenericApplicationContext()) {
            context.refresh();
            ConfigurableListableBeanFactory beanFactory = context
                    .getBeanFactory();

            beanFactory.registerSingleton("FIRST", new Object());
            String[] beanNames = beanFactory.getBeanNamesForType(Object.class);

            beanFactory.registerSingleton("SECOND", new HashMap<String, Object>());

            beanNames = beanFactory.getBeanNamesForType(Object.class);
            System.out.println(Arrays.toString(beanNames));

        }

The result with Spring 6.2.10/6.2.11 is:
[environment, systemProperties, systemEnvironment, applicationStartup, messageSource, applicationEventMulticaster, lifecycleProcessor, FIRST] - > "SECOND" is missing

Whereas with earlier version the array contains "SECOND" as well.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions