diff options
author | vt512 <vt512@users.noreply.github.com> | 2020-09-08 16:29:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-08 17:29:17 +0300 |
commit | bafab4554a43f7c0214e919fa9d594a92305bc92 (patch) | |
tree | 1ec81b39cf637b933ab81b883b49b5be01a00d12 | |
parent | 665f3355a2f6a759ca7ee088025a4546c3953b02 (diff) | |
download | vaadin-framework-bafab4554a43f7c0214e919fa9d594a92305bc92.tar.gz vaadin-framework-bafab4554a43f7c0214e919fa9d594a92305bc92.zip |
fix duplicate key exception with Binder when interface method is overwritten (#12091)
-rw-r--r-- | server/src/main/java/com/vaadin/data/BeanPropertySet.java | 2 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/data/BeanBinderTest.java | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/data/BeanPropertySet.java b/server/src/main/java/com/vaadin/data/BeanPropertySet.java index 90c264eaa1..bd856c23f8 100644 --- a/server/src/main/java/com/vaadin/data/BeanPropertySet.java +++ b/server/src/main/java/com/vaadin/data/BeanPropertySet.java @@ -313,7 +313,7 @@ public class BeanPropertySet<T> implements PropertySet<T> { .map(descriptor -> new BeanPropertyDefinition<>(this, instanceKey.type, descriptor)) .collect(Collectors.toMap(PropertyDefinition::getName, - Function.identity())); + Function.identity(), (pd1, pd2) -> pd2)); } catch (IntrospectionException e) { throw new IllegalArgumentException( "Cannot find property descriptors for " diff --git a/server/src/test/java/com/vaadin/data/BeanBinderTest.java b/server/src/test/java/com/vaadin/data/BeanBinderTest.java index bdcfb16d7b..2b29303c78 100644 --- a/server/src/test/java/com/vaadin/data/BeanBinderTest.java +++ b/server/src/test/java/com/vaadin/data/BeanBinderTest.java @@ -21,6 +21,7 @@ import org.junit.Test; import com.vaadin.data.BeanBinderTest.RequiredConstraints.SubConstraint; import com.vaadin.data.BeanBinderTest.RequiredConstraints.SubSubConstraint; +import com.vaadin.data.BinderInstanceFieldTest.IntegerTextField; import com.vaadin.data.converter.StringToIntegerConverter; import com.vaadin.tests.data.bean.BeanToValidate; import com.vaadin.ui.CheckBoxGroup; @@ -167,6 +168,15 @@ public class BeanBinderTest private TextField mydate = new TextField(); } + public interface TestInterface { + int getProperty(); + } + + public interface TestInterfaceWithOverwrittenMethod extends TestInterface { + @Override + int getProperty(); + } + @Before public void setUp() { binder = new BeanValidationBinder<>(BeanToValidate.class); @@ -537,6 +547,24 @@ public class BeanBinderTest assertTrue(binder.validate().isOk()); } + @Test + public void interface_extension_with_overwritten_property() { + Binder<TestInterfaceWithOverwrittenMethod> binder = new Binder<>( + TestInterfaceWithOverwrittenMethod.class); + IntegerTextField field = new IntegerTextField(); + + binder.bind(field, "property"); + TestInterfaceWithOverwrittenMethod bean = new TestInterfaceWithOverwrittenMethod() { + @Override + public int getProperty() { + return 5; + } + }; + binder.setBean(bean); + + assertEquals(Integer.valueOf(5), field.getValue()); + } + private void assertInvalid(HasValue<?> field, String message) { BinderValidationStatus<?> status = binder.validate(); List<BindingValidationStatus<?>> errors = status |