Avoid ConcurrentModificationException in getBeansWithAnnotation

Issue: SPR-12688
master
Juergen Hoeller 10 years ago
parent 13ccc8ede8
commit 918bc3b103
  1. 17
      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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -562,17 +562,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Override @Override
public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) { public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) {
Map<String, Object> results = new LinkedHashMap<String, Object>(); String[] beanNames = getBeanNamesForAnnotation(annotationType);
for (String beanName : this.beanDefinitionNames) { Map<String, Object> results = new LinkedHashMap<String, Object>(beanNames.length);
BeanDefinition beanDefinition = getBeanDefinition(beanName); for (String beanName : beanNames) {
if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) { results.put(beanName, getBean(beanName));
results.put(beanName, getBean(beanName));
}
}
for (String beanName : this.manualSingletonNames) {
if (!results.containsKey(beanName) && findAnnotationOnBean(beanName, annotationType) != null) {
results.put(beanName, getBean(beanName));
}
} }
return results; return results;
} }

Loading…
Cancel
Save