Properly handle null bean instance in getLifecycleBeans

Issue: SPR-16343
master
Juergen Hoeller 7 years ago
parent 18d90ec140
commit 977550f956
  1. 8
      spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -285,9 +285,9 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
if ((getBeanFactory().containsSingleton(beanNameToRegister) && if ((getBeanFactory().containsSingleton(beanNameToRegister) &&
(!isFactoryBean || matchesBeanType(Lifecycle.class, beanNameToCheck))) || (!isFactoryBean || matchesBeanType(Lifecycle.class, beanNameToCheck))) ||
matchesBeanType(SmartLifecycle.class, beanNameToCheck)) { matchesBeanType(SmartLifecycle.class, beanNameToCheck)) {
Lifecycle bean = getBeanFactory().getBean(beanNameToCheck, Lifecycle.class); Object bean = getBeanFactory().getBean(beanNameToCheck);
if (bean != this) { if (bean != this && bean instanceof Lifecycle) {
beans.put(beanNameToRegister, bean); beans.put(beanNameToRegister, (Lifecycle) bean);
} }
} }
} }

Loading…
Cancel
Save