Commit ebae76b1 authored by Phillip Webb's avatar Phillip Webb

Protect against null BindHandler.onStart result

Fixes gh-18129
parent 1851f711
......@@ -285,10 +285,11 @@ public class Binder {
boolean allowRecursiveBinding, boolean create) {
context.clearConfigurationProperty();
try {
target = handler.onStart(name, target, context);
if (target == null) {
Bindable<T> replacementTarget = handler.onStart(name, target, context);
if (replacementTarget == null) {
return handleBindResult(name, target, handler, context, null, create);
}
target = replacementTarget;
Object bound = bindObject(name, target, handler, context, allowRecursiveBinding);
return handleBindResult(name, target, handler, context, bound, create);
}
......
......@@ -318,6 +318,20 @@ class BinderTests {
assertThat(value).isInstanceOf(JavaBean.class);
}
@Test
void bindToJavaBeanWhenHandlerOnStartReturnsNullShouldReturnUnbound() { // gh-18129
this.sources.add(new MockConfigurationPropertySource("foo.value", "bar"));
BindResult<JavaBean> result = this.binder.bind("foo", Bindable.of(JavaBean.class), new BindHandler() {
@Override
public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) {
return null;
}
});
assertThat(result.isBound()).isFalse();
}
static class JavaBean {
private String 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