Skip to content

ConcurrentModificationException in AbstractApplicationContext.getBeansOfType() [SPR-259] #4990

Closed
@spring-projects-issues

Description

@spring-projects-issues

Torsten Juergeleit opened SPR-259 and commented

Concurrent calls from within different threads (servlets) to AbstractApplicationContext.getBeansOfType() leads to the following exception:

java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:782)
at java.util.HashMap$KeyIterator.next(HashMap.java:818)
at org.springframework.beans.factory.support.AbstractBeanFactory.getSingletonNames(AbstractBeanFactory.java:481)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:1
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:468)
at de.deka.techarch.spring.bean.BeanUtils.getFirstInterceptedBeanOfType(BeanUtils.java:67)
at de.deka.dekanet.service.context.BusinessServiceFactory.getService(BusinessServiceFactory.java:86)

Our code which calls ListableBeanFactory.getBeansOfType() is as follows:

/**
 * Returns the first bean from the {@link Map} returned by
 * <code>ListableBeanFactory.getBeansOfType(type, true, true)</code>
 * which is an instances of {@link java.lang.reflect.Proxy}</code>.
 */
public static final Object getFirstProxiedBeanOfType(
								ListableBeanFactory factory, Class type) {
	Map names = factory.getBeansOfType(type, true, true);
	Iterator iter = names.keySet().iterator();
	while (iter.hasNext()) {
		String name = (String)iter.next();
		Object bean = factory.getBean(name);
		if (bean instanceof Proxy) {
			return bean;
		}
	}
	return null;
}

Affects: 1.1 RC1

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions