Avoid NPE on BeanDescriptor access with SimpleBeanInfoFactory
Closes gh-29681
This commit is contained in:
parent
4c69892f39
commit
d74191427e
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.beans;
|
package org.springframework.beans;
|
||||||
|
|
||||||
|
import java.beans.BeanDescriptor;
|
||||||
import java.beans.BeanInfo;
|
import java.beans.BeanInfo;
|
||||||
import java.beans.IntrospectionException;
|
import java.beans.IntrospectionException;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
|
@ -52,6 +53,10 @@ class SimpleBeanInfoFactory implements BeanInfoFactory, Ordered {
|
||||||
PropertyDescriptorUtils.determineBasicProperties(beanClass);
|
PropertyDescriptorUtils.determineBasicProperties(beanClass);
|
||||||
|
|
||||||
return new SimpleBeanInfo() {
|
return new SimpleBeanInfo() {
|
||||||
|
@Override
|
||||||
|
public BeanDescriptor getBeanDescriptor() {
|
||||||
|
return new BeanDescriptor(beanClass);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||||
return pds.toArray(PropertyDescriptorUtils.EMPTY_PROPERTY_DESCRIPTOR_ARRAY);
|
return pds.toArray(PropertyDescriptorUtils.EMPTY_PROPERTY_DESCRIPTOR_ARRAY);
|
||||||
|
|
|
@ -77,6 +77,21 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||||
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
|
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void replaceWrappedInstance() {
|
||||||
|
GetterBean target = new GetterBean();
|
||||||
|
BeanWrapperImpl accessor = createAccessor(target);
|
||||||
|
accessor.setPropertyValue("name", "tom");
|
||||||
|
assertThat(target.getAliasedName()).isEqualTo("tom");
|
||||||
|
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
|
||||||
|
|
||||||
|
target = new GetterBean();
|
||||||
|
accessor.setWrappedInstance(target);
|
||||||
|
accessor.setPropertyValue("name", "tom");
|
||||||
|
assertThat(target.getAliasedName()).isEqualTo("tom");
|
||||||
|
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() {
|
void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() {
|
||||||
TestBean target = new TestBean();
|
TestBean target = new TestBean();
|
||||||
|
|
Loading…
Reference in New Issue