Skip to content

Commit 201885a

Browse files
izeyemhalbritter
authored andcommitted
Fix target in BindValidationFailureAnalyzer
See gh-40035
1 parent 3b98056 commit 201885a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BindValidationFailureAnalyzer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ protected FailureAnalysis analyze(Throwable rootFailure, Throwable cause) {
4747
private ExceptionDetails getBindValidationExceptionDetails(Throwable rootFailure) {
4848
BindValidationException validationException = findCause(rootFailure, BindValidationException.class);
4949
if (validationException != null) {
50-
BindException target = findCause(rootFailure, BindException.class);
50+
BindException bindException = findCause(rootFailure, BindException.class);
5151
List<ObjectError> errors = validationException.getValidationErrors().getAllErrors();
52-
return new ExceptionDetails(errors, target, validationException);
52+
return new ExceptionDetails(errors, bindException.getTarget().getType(), validationException);
5353
}
5454
org.springframework.validation.BindException bindException = findCause(rootFailure,
5555
org.springframework.validation.BindException.class);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindValidationFailureAnalyzerTests.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ void cleanup() {
6363
@Test
6464
void bindExceptionWithFieldErrorsDueToValidationFailure() {
6565
FailureAnalysis analysis = performAnalysis(FieldValidationFailureConfiguration.class);
66-
assertThat(analysis.getDescription()).contains(failure("test.foo.foo", "null", "must not be null"));
67-
assertThat(analysis.getDescription()).contains(failure("test.foo.value", "0", "at least five"));
68-
assertThat(analysis.getDescription()).contains(failure("test.foo.nested.bar", "null", "must not be null"));
66+
assertThat(analysis.getDescription()).contains(failure("test.foo.foo", "null", "must not be null"))
67+
.contains(failure("test.foo.value", "0", "at least five"))
68+
.contains(failure("test.foo.nested.bar", "null", "must not be null"))
69+
.contains(
70+
"Binding to target org.springframework.boot.diagnostics.analyzer.BindValidationFailureAnalyzerTests$FieldValidationFailureProperties failed:");
6971
}
7072

7173
@Test

0 commit comments

Comments
 (0)