From a50d1f0bd64186197beca3306fefafff8ae57234 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 16 Nov 2022 16:28:08 -0800 Subject: [PATCH] Switch to use BeanUtils.getPropertyDescriptors Update `BindableRuntimeHintsRegistrar` to use `BeanUtils.getPropertyDescriptors` rather than `BeanInfoFactory`. Closes gh-33232 --- .../bind/BindableRuntimeHintsRegistrar.java | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindableRuntimeHintsRegistrar.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindableRuntimeHintsRegistrar.java index b0b7154a6490..69ec3bb95e6e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindableRuntimeHintsRegistrar.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindableRuntimeHintsRegistrar.java @@ -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; @@ -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; /** @@ -59,8 +56,6 @@ */ public class BindableRuntimeHintsRegistrar implements RuntimeHintsRegistrar { - private static final BeanInfoFactory beanInfoFactory = new ExtendedBeanInfoFactory(); - private final Class[] types; /** @@ -120,7 +115,7 @@ private final class Processor { private final Constructor bindConstructor; - private final BeanInfo beanInfo; + private final PropertyDescriptor[] propertyDescriptors; private final Set> seen; @@ -134,24 +129,11 @@ private Processor(Class type, boolean nestedType, Set> seen, Set> 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; @@ -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); } } @@ -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);