Merge pull request #50798 from xfocus3

Closes gh-50798

* gh-50798:
  Handle unresolved validation target types
This commit is contained in:
Andy Wilkinson
2026-06-24 21:11:52 +01:00
2 changed files with 25 additions and 3 deletions
@@ -34,7 +34,6 @@ import org.springframework.boot.context.properties.source.ConfigurationProperty;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName.Form;
import org.springframework.core.ResolvableType;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.AbstractBindingResult;
import org.springframework.validation.BeanPropertyBindingResult;
@@ -115,8 +114,7 @@ public class ValidationBindHandler extends AbstractBindHandler {
if (this.exception == null) {
Object validationTarget = getValidationTarget(target, context, result);
Class<?> validationType = target.getBoxedType().resolve();
if (validationTarget != null) {
Assert.state(validationType != null, "'validationType' must not be null");
if (validationTarget != null && validationType != null) {
validateAndPush(name, validationTarget, validationType);
}
}
@@ -238,6 +238,15 @@ class ValidationBindHandlerTests {
this.binder.bind(ConfigurationPropertyName.of("test"), Bindable.of(ExampleWithMap.class), this.handler);
}
@Test
void bindShouldValidateMapWithWildcardValue() {
this.sources.add(new MockConfigurationPropertySource("test.params.toto", "titi"));
ExampleWithWildcardMap result = this.binder
.bind(ConfigurationPropertyName.of("test"), Bindable.of(ExampleWithWildcardMap.class), this.handler)
.get();
assertThat(result.getParams().get("toto")).isEqualTo("titi");
}
private Validator getMapValidator() {
return new Validator() {
@@ -425,6 +434,21 @@ class ValidationBindHandlerTests {
}
@Validated
static class ExampleWithWildcardMap {
private Map<String, ?> params = new LinkedHashMap<>();
Map<String, ?> getParams() {
return this.params;
}
void setParams(Map<String, ?> params) {
this.params = params;
}
}
static class ExampleMapValue {
private @Nullable String number;