From 0a74a6c589e203a259235ea36d6b4ae8513e61f4 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sun, 3 Nov 2019 17:29:44 +0300 Subject: [PATCH] Remove removed binding from changedBinding field Fixes #5384 --- .../com/vaadin/flow/data/binder/Binder.java | 10 +++++--- .../vaadin/flow/data/binder/BinderTest.java | 23 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java b/flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java index fbb325d0f02..6263c2a3378 100644 --- a/flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java +++ b/flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java @@ -566,9 +566,11 @@ default BindingBuilder withNullRepresentation( TARGET nullRepresentation) { return withConverter( fieldValue -> Objects.equals(fieldValue, nullRepresentation) - ? null : fieldValue, + ? null + : fieldValue, modelValue -> Objects.isNull(modelValue) - ? nullRepresentation : modelValue); + ? nullRepresentation + : modelValue); } /** @@ -2503,7 +2505,8 @@ private Converter createNullRepresentationA Converter nullRepresentationConverter = Converter .from(fieldValue -> fieldValue, modelValue -> Objects.isNull(modelValue) - ? field.getEmptyValue() : modelValue, + ? field.getEmptyValue() + : modelValue, Throwable::getMessage); ConverterDelegate converter = new ConverterDelegate<>( nullRepresentationConverter); @@ -2882,6 +2885,7 @@ protected void removeBindingInternal(Binding binding) { if (bindings.remove(binding)) { boundProperties.entrySet() .removeIf(entry -> entry.getValue().equals(binding)); + changedBindings.remove(binding); } } diff --git a/flow-data/src/test/java/com/vaadin/flow/data/binder/BinderTest.java b/flow-data/src/test/java/com/vaadin/flow/data/binder/BinderTest.java index 2c8258e015d..e953d78e729 100644 --- a/flow-data/src/test/java/com/vaadin/flow/data/binder/BinderTest.java +++ b/flow-data/src/test/java/com/vaadin/flow/data/binder/BinderTest.java @@ -121,6 +121,23 @@ public void bindNullBean_FieldsAreCleared() { assertEquals("Age field not empty", "", ageField.getValue()); } + @Test + public void removeInvalidBinding_validateDoesNotThrow() { + binder.forField(nameField).bind(Person::getFirstName, + Person::setFirstName); + Binding ageBinding = binder.forField(ageField) + .withConverter(new StringToIntegerConverter("")) + .bind(Person::getAge, Person::setAge); + binder.withValidator(bean -> true, ""); + binder.setBean(item); + + ageField.setValue("foo"); + + binder.removeBinding(ageBinding); + + binder.validate(); + } + @Test public void clearForReadBean_boundFieldsAreCleared() { binder.forField(nameField).bind(Person::getFirstName, @@ -451,8 +468,9 @@ public void beanBinder_withConverter_nullRepresentationIsNotDisabled() { String customNullPointerRepresentation = "foo"; Binder binder = new Binder<>(Person.class); binder.forField(nameField) - .withConverter(value -> value, value -> value == null - ? customNullPointerRepresentation : value) + .withConverter(value -> value, + value -> value == null ? customNullPointerRepresentation + : value) .bind("firstName"); Person person = new Person(); @@ -1345,7 +1363,6 @@ public void nullRejetingField_nullValue_wrappedExceptionMentionsNullRepresentati binder.readBean(new AtomicReference<>()); } - @Test public void nullRejetingField_otherRejectedValue_originalExceptionIsThrown() { TestTextField field = createNullRejectingFieldWithEmptyValue("");