From 5aa6433972b2b0980bcb9a658f28a72e426453f8 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 19 Mar 2018 18:57:26 +0200 Subject: [PATCH] Add missing null check to Binding (#10726) * Add missing null check to Binding --- .../src/main/java/com/vaadin/data/Binder.java | 8 +++++--- .../test/java/com/vaadin/data/BinderTest.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java index 406784fda4..769ca74bed 100644 --- a/server/src/main/java/com/vaadin/data/Binder.java +++ b/server/src/main/java/com/vaadin/data/Binder.java @@ -1139,9 +1139,11 @@ public class Binder implements Serializable { */ private void handleFieldValueChange( ValueChangeEvent event) { - // Inform binder of changes; if setBean: writeIfValid - getBinder().handleFieldValueChange(this, event); - getBinder().fireValueChangeEvent(event); + if (binder != null) { + // Inform binder of changes; if setBean: writeIfValid + getBinder().handleFieldValueChange(this, event); + getBinder().fireValueChangeEvent(event); + } } /** diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java index 5988061cd5..abbbe541ae 100644 --- a/server/src/test/java/com/vaadin/data/BinderTest.java +++ b/server/src/test/java/com/vaadin/data/BinderTest.java @@ -811,6 +811,25 @@ public class BinderTest extends BinderTestBase, Person> { String.valueOf(item.getAge()), ageField.getValue()); } + @Test + public void remove_binding_fromFieldValueChangeListener() { + // Add listener before bind to make sure it will be executed first. + nameField.addValueChangeListener(e -> { + if (e.getValue() == "REMOVE") { + binder.removeBinding(nameField); + } + }); + + binder.bind(nameField, Person::getFirstName, Person::setFirstName); + + binder.setBean(item); + + nameField.setValue("REMOVE"); + + // Removed binding should not update bean. + assertNotEquals("REMOVE", item.getFirstName()); + } + @Test public void beanvalidation_two_fields_not_equal() { TextField lastNameField = new TextField(); -- 2.39.5