Skip to content

Commit

Permalink
fix: Fix regression NPE in binder (#18623)
Browse files Browse the repository at this point in the history
This patch fixes a regression in Binder introduced by adding skipDefaultValidator API (#18549). This issue was missed since it seems to be impossible/difficult to trigger via unit testing using the mock field components in Flow project.

Affected flow-components tests:
UpdateEditorComponentIT
DynamicEditorKBNavigationIT
GridViewEditorIT.dynamicNotBufferedEditor_closeEditorUsingKeyboard
GridViewEditorIT.dynamicNotBufferedEditor
GridViewEditorIT.dynamicNotBufferedEditor_navigateUsingKeyboard

Fixes #18608
  • Loading branch information
tepi authored and rodolforfq committed Feb 7, 2024
1 parent 81f17a5 commit 0dc98d7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java
Expand Up @@ -1006,9 +1006,12 @@ protected BindingBuilderImpl(Binder<BEAN> binder,
this.statusHandler = statusHandler;

if (field instanceof HasValidator hasValidator) {
withValidator((val, ctx) -> binding.isDefaultValidatorDisabled()
? ValidationResult.ok()
: hasValidator.getDefaultValidator().apply(val, ctx));
withValidator((val,
ctx) -> binding != null
&& binding.isDefaultValidatorDisabled()
? ValidationResult.ok()
: hasValidator.getDefaultValidator()
.apply(val, ctx));
}
}

Expand All @@ -1024,6 +1027,12 @@ public Binding<BEAN, TARGET> bind(ValueProvider<BEAN, TARGET> getter,

BindingImpl<BEAN, FIELDVALUE, TARGET> binding = new BindingImpl<>(
this, getter, setter);
// Setting the binding field value has been moved up here to fix a
// regression NPE https://github.com/vaadin/flow/issues/18608 which
// breaks tests of Grid component: UpdateEditorComponentIT,
// DynamicEditorKBNavigationIT and
// GridViewEditorIT.dynamicNotBufferedEditor*
this.binding = binding;

// Remove existing binding for same field to avoid potential
// multiple application of converter
Expand All @@ -1042,7 +1051,6 @@ public Binding<BEAN, TARGET> bind(ValueProvider<BEAN, TARGET> getter,
if (getBinder().incompleteBindings != null) {
getBinder().incompleteBindings.remove(getField());
}
this.binding = binding;

return binding;
}
Expand Down

0 comments on commit 0dc98d7

Please sign in to comment.