Skip to content

Doc: DefaultListableBeanFactory is not thread-safe for manual singleton registration [SPR-12970] #17562

Closed
@spring-projects-issues

Description

@spring-projects-issues

Mariano Gonzalez opened SPR-12970 and commented

Although the DefaultListableBeanFactory class uses ConcurrentHashMap to keep track of the contained objects, the manualSingletonNames is a simple LinkedHashMap.

As a result, if a Thread is manually registering a bean via the registerSingleton(String, Object) method, while another thread is executing the doGetBeanNamesForType(Class, boolean, boolean) -- or any of the other methods which iterate that Set -- then a ConcurrentModificationException is thrown.

It seems to me that this should be allowed and that if the maps are concurrent, then it makes sense that this Set is also.

Additionally I noticed that the beanDefinitionNames and resolvableDependencies attributes are also not synchronised. I haven't run into any issues with that, but it's still worth analysing.

Thank you!


Affects: 4.1.6

Issue Links:

Referenced from: commits 90493f4

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions