Skip to content

Commit 37fa82c

Browse files
committed
Lenient rejectedValue lookup in SpringValidatorAdapter
Closes gh-29043
1 parent 1f2d29e commit 37fa82c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import jakarta.validation.metadata.BeanDescriptor;
3333
import jakarta.validation.metadata.ConstraintDescriptor;
3434

35+
import org.springframework.beans.InvalidPropertyException;
3536
import org.springframework.beans.NotReadablePropertyException;
3637
import org.springframework.context.MessageSourceResolvable;
3738
import org.springframework.context.support.DefaultMessageSourceResolvable;
@@ -312,7 +313,13 @@ protected Object getRejectedValue(String field, ConstraintViolation<Object> viol
312313
(invalidValue == violation.getLeafBean() || field.contains("[") || field.contains("."))) {
313314
// Possibly a bean constraint with property path: retrieve the actual property value.
314315
// However, explicitly avoid this for "address[]" style paths that we can't handle.
315-
invalidValue = bindingResult.getRawFieldValue(field);
316+
try {
317+
invalidValue = bindingResult.getRawFieldValue(field);
318+
}
319+
catch (InvalidPropertyException ex) {
320+
// Bean validation uses ValueExtractor's to unwrap container values
321+
// in which cases we can't access the raw value.
322+
}
316323
}
317324
return invalidValue;
318325
}

0 commit comments

Comments
 (0)