]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make CheckBoxGroup.SimpleMultiSelectModel return a selection copy #293.
authorDenis Anisimov <denis@vaadin.com>
Fri, 16 Sep 2016 18:57:40 +0000 (21:57 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 21 Sep 2016 09:02:55 +0000 (09:02 +0000)
getSelectedItems() must return a copy to fulfill the contract specified
in SelectionModel: it must be a snapshot of the current state and safe
to iterate over while changing selection.

Change-Id: Ie2f15eb626dd80df2036bcb2d4e9387fc31389c9

server/src/main/java/com/vaadin/ui/CheckBoxGroup.java
server/src/test/java/com/vaadin/data/BinderMultiSelectTest.java

index 8525dc6cbb7f13b319dfd0a3057015ef02256e52..d5b2c5a8515fff55a4812ab04b60283090d31f99 100644 (file)
@@ -71,7 +71,7 @@ public class CheckBoxGroup<T> extends AbstractMultiSelect<T> {
 
         @Override
         public Set<T> getSelectedItems() {
-            return Collections.unmodifiableSet(selection);
+            return Collections.unmodifiableSet(new LinkedHashSet<>(selection));
         }
 
         @Override
index 93f4ccdac4a696b018a60e4428acae7977cdea7a..fd75c930f3f944546ba8081ffda18779f68e9fe6 100644 (file)
@@ -117,6 +117,20 @@ public class BinderMultiSelectTest
         assertEquals(Collections.singleton(TestEnum.TWO), item.getEnums());
     }
 
+    @Test
+    public void bound_setSelection_beanValueIsACopy() {
+        bindEnum();
+
+        select.select(TestEnum.TWO);
+
+        Set<TestEnum> enums = item.getEnums();
+
+        binder.bind(new BeanWithEnums());
+        select.select(TestEnum.ONE);
+
+        assertEquals(Collections.singleton(TestEnum.TWO), enums);
+    }
+
     @Test
     public void bound_deselect_beanValueUpdatedToNull() {
         item.setEnums(Collections.singleton(TestEnum.ONE));