Skip to content

Commit 8c80ec1

Browse files
committed
Avoid NPE on BeanDescriptor access with SimpleBeanInfoFactory
Closes gh-29681 (cherry picked from commit d741914)
1 parent 912fa76 commit 8c80ec1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.beans;
1818

19+
import java.beans.BeanDescriptor;
1920
import java.beans.BeanInfo;
2021
import java.beans.IntrospectionException;
2122
import java.beans.PropertyDescriptor;
@@ -51,6 +52,10 @@ public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
5152
PropertyDescriptorUtils.determineBasicProperties(beanClass);
5253

5354
return new SimpleBeanInfo() {
55+
@Override
56+
public BeanDescriptor getBeanDescriptor() {
57+
return new BeanDescriptor(beanClass);
58+
}
5459
@Override
5560
public PropertyDescriptor[] getPropertyDescriptors() {
5661
return pds.toArray(PropertyDescriptorUtils.EMPTY_PROPERTY_DESCRIPTOR_ARRAY);

spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ void aliasedSetterThroughDefaultMethod() {
7777
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
7878
}
7979

80+
@Test
81+
void replaceWrappedInstance() {
82+
GetterBean target = new GetterBean();
83+
BeanWrapperImpl accessor = createAccessor(target);
84+
accessor.setPropertyValue("name", "tom");
85+
assertThat(target.getAliasedName()).isEqualTo("tom");
86+
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
87+
88+
target = new GetterBean();
89+
accessor.setWrappedInstance(target);
90+
accessor.setPropertyValue("name", "tom");
91+
assertThat(target.getAliasedName()).isEqualTo("tom");
92+
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
93+
}
94+
8095
@Test
8196
void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() {
8297
TestBean target = new TestBean();

0 commit comments

Comments
 (0)