Skip to content

Commit

Permalink
Avoid NPE on BeanDescriptor access with SimpleBeanInfoFactory
Browse files Browse the repository at this point in the history
Closes gh-29681
  • Loading branch information
jhoeller committed Dec 13, 2022
1 parent 4c69892 commit d741914
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Expand Up @@ -16,6 +16,7 @@

package org.springframework.beans;

import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
Expand Down Expand Up @@ -52,6 +53,10 @@ public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
PropertyDescriptorUtils.determineBasicProperties(beanClass);

return new SimpleBeanInfo() {
@Override
public BeanDescriptor getBeanDescriptor() {
return new BeanDescriptor(beanClass);
}
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
return pds.toArray(PropertyDescriptorUtils.EMPTY_PROPERTY_DESCRIPTOR_ARRAY);
Expand Down
Expand Up @@ -77,6 +77,21 @@ void aliasedSetterThroughDefaultMethod() {
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
void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() {
TestBean target = new TestBean();
Expand Down

0 comments on commit d741914

Please sign in to comment.