]> source.dussan.org Git - vaadin-framework.git/commitdiff
fix duplicate key exception with Binder when interface method is overwritten (#12091)
authorvt512 <vt512@users.noreply.github.com>
Tue, 8 Sep 2020 14:29:17 +0000 (16:29 +0200)
committerGitHub <noreply@github.com>
Tue, 8 Sep 2020 14:29:17 +0000 (17:29 +0300)
server/src/main/java/com/vaadin/data/BeanPropertySet.java
server/src/test/java/com/vaadin/data/BeanBinderTest.java

index 90c264eaa1f7006da75d34c5df433cd88347d536..bd856c23f8296b6cc2beedb2acbf832fe5caa052 100644 (file)
@@ -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 "
index bdcfb16d7b5e947f253e7bbdbeaba6b31c2f65dd..2b29303c784b5eca6da05cab925730b5376312ed 100644 (file)
@@ -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