Commit 9c8d2c80 authored by Andy Wilkinson's avatar Andy Wilkinson

Improve analysis of bind failures caused by a conversion failure

Closes gh-13357
parent ea51cfab
...@@ -70,6 +70,12 @@ class BindFailureAnalyzer extends AbstractFailureAnalyzer<BindException> { ...@@ -70,6 +70,12 @@ class BindFailureAnalyzer extends AbstractFailureAnalyzer<BindException> {
} }
private String getMessage(BindException cause) { 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; Throwable failure = cause;
while (failure.getCause() != null) { while (failure.getCause() != null) {
failure = failure.getCause(); failure = failure.getCause();
......
...@@ -62,10 +62,10 @@ public class BindFailureAnalyzerTests { ...@@ -62,10 +62,10 @@ public class BindFailureAnalyzerTests {
@Test @Test
public void bindExceptionDueToOtherFailure() { public void bindExceptionDueToOtherFailure() {
FailureAnalysis analysis = performAnalysis(GenericFailureConfiguration.class, FailureAnalysis analysis = performAnalysis(GenericFailureConfiguration.class,
"test.foo.value=${BAR}"); "test.foo.value=alpha");
assertThat(analysis.getDescription()).contains(failure("test.foo.value", "${BAR}", assertThat(analysis.getDescription()).contains(failure("test.foo.value", "alpha",
"\"test.foo.value\" from property source \"test\"", "\"test.foo.value\" from property source \"test\"",
"Could not resolve placeholder 'BAR' in value \"${BAR}\"")); "failed to convert java.lang.String to int"));
} }
@Test @Test
...@@ -187,13 +187,13 @@ public class BindFailureAnalyzerTests { ...@@ -187,13 +187,13 @@ public class BindFailureAnalyzerTests {
@ConfigurationProperties("test.foo") @ConfigurationProperties("test.foo")
static class GenericFailureProperties { static class GenericFailureProperties {
private String value; private int value;
public String getValue() { public int getValue() {
return this.value; return this.value;
} }
public void setValue(String value) { public void setValue(int value) {
this.value = value; this.value = value;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment