Improve analysis of bind failures caused by a conversion failure
Closes gh-13357
This commit is contained in:
@@ -70,6 +70,12 @@ class BindFailureAnalyzer extends AbstractFailureAnalyzer<BindException> {
|
||||
}
|
||||
|
||||
private String getMessage(BindException cause) {
|
||||
ConversionFailedException conversionFailure = findCause(cause,
|
||||
ConversionFailedException.class);
|
||||
if (conversionFailure != null) {
|
||||
return "failed to convert " + conversionFailure.getSourceType() + " to "
|
||||
+ conversionFailure.getTargetType();
|
||||
}
|
||||
Throwable failure = cause;
|
||||
while (failure.getCause() != null) {
|
||||
failure = failure.getCause();
|
||||
|
||||
@@ -62,10 +62,10 @@ public class BindFailureAnalyzerTests {
|
||||
@Test
|
||||
public void bindExceptionDueToOtherFailure() {
|
||||
FailureAnalysis analysis = performAnalysis(GenericFailureConfiguration.class,
|
||||
"test.foo.value=${BAR}");
|
||||
assertThat(analysis.getDescription()).contains(failure("test.foo.value", "${BAR}",
|
||||
"test.foo.value=alpha");
|
||||
assertThat(analysis.getDescription()).contains(failure("test.foo.value", "alpha",
|
||||
"\"test.foo.value\" from property source \"test\"",
|
||||
"Could not resolve placeholder 'BAR' in value \"${BAR}\""));
|
||||
"failed to convert java.lang.String to int"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,13 +187,13 @@ public class BindFailureAnalyzerTests {
|
||||
@ConfigurationProperties("test.foo")
|
||||
static class GenericFailureProperties {
|
||||
|
||||
private String value;
|
||||
private int value;
|
||||
|
||||
public String getValue() {
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user