From f3f8610539369e03992e1fd5604cb51ae334ba2d Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 16 Jun 2023 10:17:08 -0700 Subject: [PATCH] Polish --- .../hazelcast/hazelcast-client-instance.xml | 4 --- .../ConfigurationPropertiesBinder.java | 31 ++++++++++++------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml index 750a658d798..5497f784de4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml @@ -2,19 +2,15 @@ - spring-boot - 60000 -
${address}
-
diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java index d74bb84fe43..6111d8e9ed9 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java @@ -137,7 +137,6 @@ class ConfigurationPropertiesBinder { : new IgnoreTopLevelConverterNotFoundBindHandler(); } - @SuppressWarnings("unchecked") private List getValidators(Bindable target) { List validators = new ArrayList<>(3); if (this.configurationPropertiesValidator != null) { @@ -146,15 +145,23 @@ class ConfigurationPropertiesBinder { if (this.jsr303Present && target.getAnnotation(Validated.class) != null) { validators.add(getJsr303Validator()); } + Validator selfValidator = getSelfValidator(target); + if (selfValidator != null) { + validators.add(selfValidator); + } + return validators; + } + + private Validator getSelfValidator(Bindable target) { if (target.getValue() != null) { - if (target.getValue().get() instanceof Validator) { - validators.add((Validator) target.getValue().get()); - } + Object value = target.getValue().get(); + return (value instanceof Validator) ? (Validator) value : null; } - else if (Validator.class.isAssignableFrom(target.getType().resolve())) { - validators.add(new SelfValidatingConstructorBoundBindableValidator((Bindable) target)); + Class type = target.getType().resolve(); + if (Validator.class.isAssignableFrom(type)) { + return new SelfValidatingConstructorBoundBindableValidator(type); } - return validators; + return null; } private Validator getJsr303Validator() { @@ -271,15 +278,15 @@ class ConfigurationPropertiesBinder { */ static class SelfValidatingConstructorBoundBindableValidator implements Validator { - private final Bindable bindable; + private final Class type; - SelfValidatingConstructorBoundBindableValidator(Bindable bindable) { - this.bindable = bindable; + SelfValidatingConstructorBoundBindableValidator(Class type) { + this.type = type; } @Override - public boolean supports(Class clazz) { - return clazz.isAssignableFrom(this.bindable.getType().resolve()); + public boolean supports(Class candidate) { + return candidate.isAssignableFrom(this.type); } @Override