Description
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:
- DefaultListableBeanFactory should allow efficient access to current bean names [SPR-12404] #17012 DefaultListableBeanFactory should allow efficient access to current bean names
- ConcurrentModificationException in DefaultListableBeanFactory.doGetBeanNamesForType() [SPR-13123] #17714 ConcurrentModificationException in DefaultListableBeanFactory.doGetBeanNamesForType()
- ConcurrentModificationException when executing AutowireCapableBeanFactory.createBean [SPR-13493] #18071 ConcurrentModificationException when executing AutowireCapableBeanFactory.createBean
Referenced from: commits 90493f4