Skip to content

Commit

Permalink
Switch to use BeanUtils.getPropertyDescriptors
Browse files Browse the repository at this point in the history
Update `BindableRuntimeHintsRegistrar` to use
`BeanUtils.getPropertyDescriptors` rather than `BeanInfoFactory`.

Closes gh-33232

Closes gh-32851
  • Loading branch information
philwebb committed Nov 17, 2022
1 parent 2e8d766 commit a293046
Showing 1 changed file with 6 additions and 24 deletions.
Expand Up @@ -16,9 +16,6 @@

package org.springframework.boot.context.properties.bind;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand All @@ -34,14 +31,14 @@
import org.springframework.aot.hint.ReflectionHints;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.beans.BeanInfoFactory;
import org.springframework.beans.ExtendedBeanInfoFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.ResolvableType;
import org.springframework.core.StandardReflectionParameterNameDiscoverer;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;

/**
Expand All @@ -59,8 +56,6 @@
*/
public class BindableRuntimeHintsRegistrar implements RuntimeHintsRegistrar {

private static final BeanInfoFactory beanInfoFactory = new ExtendedBeanInfoFactory();

private final Class<?>[] types;

/**
Expand Down Expand Up @@ -120,7 +115,7 @@ private final class Processor {

private final Constructor<?> bindConstructor;

private final BeanInfo beanInfo;
private final PropertyDescriptor[] propertyDescriptors;

private final Set<Class<?>> seen;

Expand All @@ -134,24 +129,11 @@ private Processor(Class<?> type, boolean nestedType, Set<Class<?>> seen,
Set<Class<?>> compiledWithoutParameters) {
this.type = type;
this.bindConstructor = BindConstructorProvider.DEFAULT.getBindConstructor(Bindable.of(type), nestedType);
this.beanInfo = getBeanInfo(type);
this.propertyDescriptors = BeanUtils.getPropertyDescriptors(type);
this.seen = seen;
this.compiledWithoutParameters = compiledWithoutParameters;
}

private static BeanInfo getBeanInfo(Class<?> beanType) {
try {
BeanInfo beanInfo = beanInfoFactory.getBeanInfo(beanType);
if (beanInfo != null) {
return beanInfo;
}
return Introspector.getBeanInfo(beanType, Introspector.IGNORE_ALL_BEANINFO);
}
catch (IntrospectionException ex) {
return null;
}
}

void process(ReflectionHints hints) {
if (this.seen.contains(this.type)) {
return;
Expand All @@ -161,7 +143,7 @@ void process(ReflectionHints hints) {
if (this.bindConstructor != null) {
handleValueObjectProperties(hints);
}
else if (this.beanInfo != null) {
else if (!ObjectUtils.isEmpty(this.propertyDescriptors)) {
handleJavaBeanProperties(hints);
}
}
Expand Down Expand Up @@ -196,7 +178,7 @@ private void handleValueObjectProperties(ReflectionHints hints) {
}

private void handleJavaBeanProperties(ReflectionHints hints) {
for (PropertyDescriptor propertyDescriptor : this.beanInfo.getPropertyDescriptors()) {
for (PropertyDescriptor propertyDescriptor : this.propertyDescriptors) {
Method writeMethod = propertyDescriptor.getWriteMethod();
if (writeMethod != null) {
hints.registerMethod(writeMethod, ExecutableMode.INVOKE);
Expand Down

0 comments on commit a293046

Please sign in to comment.