Merge branch '3.0.x' into 3.1.x

This commit is contained in:
Phillip Webb
2023-06-16 13:54:01 -07:00
13 changed files with 351 additions and 335 deletions

View File

@@ -135,7 +135,6 @@ class ConfigurationPropertiesBinder {
: new IgnoreTopLevelConverterNotFoundBindHandler();
}
@SuppressWarnings("unchecked")
private List<Validator> getValidators(Bindable<?> target) {
List<Validator> validators = new ArrayList<>(3);
if (this.configurationPropertiesValidator != null) {
@@ -144,17 +143,25 @@ class ConfigurationPropertiesBinder {
if (this.jsr303Present && target.getAnnotation(Validated.class) != null) {
validators.add(getJsr303Validator());
}
if (target.getValue() != null) {
if (target.getValue().get() instanceof Validator validator) {
validators.add(validator);
}
}
else if (Validator.class.isAssignableFrom(target.getType().resolve())) {
validators.add(new SelfValidatingConstructorBoundBindableValidator((Bindable<? extends Validator>) target));
Validator selfValidator = getSelfValidator(target);
if (selfValidator != null) {
validators.add(selfValidator);
}
return validators;
}
private Validator getSelfValidator(Bindable<?> target) {
if (target.getValue() != null) {
Object value = target.getValue().get();
return (value instanceof Validator validator) ? validator : null;
}
Class<?> type = target.getType().resolve();
if (Validator.class.isAssignableFrom(type)) {
return new SelfValidatingConstructorBoundBindableValidator(type);
}
return null;
}
private Validator getJsr303Validator() {
if (this.jsr303Validator == null) {
this.jsr303Validator = new ConfigurationPropertiesJsr303Validator(this.applicationContext);
@@ -263,15 +270,15 @@ class ConfigurationPropertiesBinder {
*/
static class SelfValidatingConstructorBoundBindableValidator implements Validator {
private final Bindable<? extends Validator> bindable;
private final Class<?> type;
SelfValidatingConstructorBoundBindableValidator(Bindable<? extends Validator> 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

View File

@@ -392,11 +392,9 @@ class JavaBeanBinder implements DataObjectBinder {
}
private boolean isUninitializedKotlinProperty(Exception ex) {
if (ex instanceof InvocationTargetException ite) {
return "kotlin.UninitializedPropertyAccessException"
.equals(ite.getTargetException().getClass().getName());
}
return false;
return (ex instanceof InvocationTargetException invocationTargetException)
&& "kotlin.UninitializedPropertyAccessException"
.equals(invocationTargetException.getTargetException().getClass().getName());
}
boolean isSettable() {