From 918bc3b1032d1cf7024f74a641d3d94e145189c7 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 10 Feb 2015 19:24:34 +0100 Subject: [PATCH] Avoid ConcurrentModificationException in getBeansWithAnnotation Issue: SPR-12688 --- .../support/DefaultListableBeanFactory.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 0a01ba17de..3052a398e5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -562,17 +562,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override public Map getBeansWithAnnotation(Class annotationType) { - Map results = new LinkedHashMap(); - for (String beanName : this.beanDefinitionNames) { - BeanDefinition beanDefinition = getBeanDefinition(beanName); - if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) { - results.put(beanName, getBean(beanName)); - } - } - for (String beanName : this.manualSingletonNames) { - if (!results.containsKey(beanName) && findAnnotationOnBean(beanName, annotationType) != null) { - results.put(beanName, getBean(beanName)); - } + String[] beanNames = getBeanNamesForAnnotation(annotationType); + Map results = new LinkedHashMap(beanNames.length); + for (String beanName : beanNames) { + results.put(beanName, getBean(beanName)); } return results; }