Don't consider singleton instances when deducing bean class
Update `RegisteredBean` bean class detection to not consider singletons. Prior to this commit, any beans that had been instantiated could return the wrong class, especially if they were implemented using a lambda. See gh-28414
This commit is contained in:
@@ -158,9 +158,6 @@ public final class RegisteredBean {
|
||||
* @return the bean class
|
||||
*/
|
||||
public Class<?> getBeanClass() {
|
||||
if (this.beanFactory.containsSingleton(getBeanName())) {
|
||||
return this.beanFactory.getSingleton(getBeanName()).getClass();
|
||||
}
|
||||
return ClassUtils.getUserClass(getBeanType().toClass());
|
||||
}
|
||||
|
||||
@@ -169,10 +166,6 @@ public final class RegisteredBean {
|
||||
* @return the bean type
|
||||
*/
|
||||
public ResolvableType getBeanType() {
|
||||
if (this.beanFactory.containsSingleton(getBeanName())) {
|
||||
return ResolvableType
|
||||
.forInstance(this.beanFactory.getSingleton(getBeanName()));
|
||||
}
|
||||
return getMergedBeanDefinition().getResolvableType();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user