Skip to content

Commit 918bc3b

Browse files
committed
Avoid ConcurrentModificationException in getBeansWithAnnotation
Issue: SPR-12688
1 parent 13ccc8e commit 918bc3b

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -562,17 +562,10 @@ public String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotation
562562

563563
@Override
564564
public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) {
565-
Map<String, Object> results = new LinkedHashMap<String, Object>();
566-
for (String beanName : this.beanDefinitionNames) {
567-
BeanDefinition beanDefinition = getBeanDefinition(beanName);
568-
if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) {
569-
results.put(beanName, getBean(beanName));
570-
}
571-
}
572-
for (String beanName : this.manualSingletonNames) {
573-
if (!results.containsKey(beanName) && findAnnotationOnBean(beanName, annotationType) != null) {
574-
results.put(beanName, getBean(beanName));
575-
}
565+
String[] beanNames = getBeanNamesForAnnotation(annotationType);
566+
Map<String, Object> results = new LinkedHashMap<String, Object>(beanNames.length);
567+
for (String beanName : beanNames) {
568+
results.put(beanName, getBean(beanName));
576569
}
577570
return results;
578571
}

0 commit comments

Comments
 (0)