From e5227ee53cfe81e2564d2999ad5405ee65017f36 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 20 Jul 2020 07:04:45 +0200 Subject: [PATCH] Defensively access existing beanDefinitionMap entries See gh-22263 (cherry picked from commit f1345aadf5879659c186a1dac7915f47d6c1cd14) --- .../beans/factory/support/DefaultListableBeanFactory.java | 5 +++-- 1 file changed, 3 insertions(+), 2 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 1caa21399d..404574d0c1 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 @@ -543,8 +543,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto public String[] getBeanNamesForAnnotation(Class annotationType) { List result = new ArrayList<>(); for (String beanName : this.beanDefinitionNames) { - BeanDefinition beanDefinition = this.beanDefinitionMap.get(beanName); - if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) { + BeanDefinition bd = this.beanDefinitionMap.get(beanName); + if (bd != null && !bd.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) { result.add(beanName); } } @@ -911,6 +911,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto for (String bdName : this.beanDefinitionNames) { if (!beanName.equals(bdName)) { BeanDefinition bd = this.beanDefinitionMap.get(bdName); + // Ensure bd is non-null due to potential concurrent modification of beanDefinitionMap. if (bd != null && beanName.equals(bd.getParentName())) { resetBeanDefinition(bdName); }