Protect against null BindHandler.onStart result
Fixes gh-18129
This commit is contained in:
parent
1851f7119f
commit
ebae76b1b8
|
@ -285,10 +285,11 @@ public class Binder {
|
||||||
boolean allowRecursiveBinding, boolean create) {
|
boolean allowRecursiveBinding, boolean create) {
|
||||||
context.clearConfigurationProperty();
|
context.clearConfigurationProperty();
|
||||||
try {
|
try {
|
||||||
target = handler.onStart(name, target, context);
|
Bindable<T> replacementTarget = handler.onStart(name, target, context);
|
||||||
if (target == null) {
|
if (replacementTarget == null) {
|
||||||
return handleBindResult(name, target, handler, context, null, create);
|
return handleBindResult(name, target, handler, context, null, create);
|
||||||
}
|
}
|
||||||
|
target = replacementTarget;
|
||||||
Object bound = bindObject(name, target, handler, context, allowRecursiveBinding);
|
Object bound = bindObject(name, target, handler, context, allowRecursiveBinding);
|
||||||
return handleBindResult(name, target, handler, context, bound, create);
|
return handleBindResult(name, target, handler, context, bound, create);
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,6 +318,20 @@ class BinderTests {
|
||||||
assertThat(value).isInstanceOf(JavaBean.class);
|
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 {
|
static class JavaBean {
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
Loading…
Reference in New Issue