diff options
author | Artur Signell <artur@vaadin.com> | 2016-10-12 21:59:08 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-10-14 11:04:34 +0000 |
commit | c7ca048dcc60b331c1b96bf4d3404a4abb18192e (patch) | |
tree | 21bf2d583d8e56dceeca4487e6d50aabb1882d0d /server | |
parent | 9c90ed78a137ba919a9b90f285a6b7e5dd5efb2b (diff) | |
download | vaadin-framework-c7ca048dcc60b331c1b96bf4d3404a4abb18192e.tar.gz vaadin-framework-c7ca048dcc60b331c1b96bf4d3404a4abb18192e.zip |
Check for duplicate property ids when setting Grid columns or column order (#20386)
Change-Id: I76be83642f0e56e55b0c0e502ac6769de1ee8af0
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/Grid.java | 11 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/grid/GridColumnsTest.java | 18 |
2 files changed, 29 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 8ca1a3de11..e7eed7725f 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -104,6 +104,7 @@ import com.vaadin.shared.ui.grid.selection.MultiSelectionModelState; import com.vaadin.shared.ui.grid.selection.SingleSelectionModelServerRpc; import com.vaadin.shared.ui.grid.selection.SingleSelectionModelState; import com.vaadin.shared.util.SharedUtil; +import com.vaadin.ui.Grid.SelectionModel; import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; import com.vaadin.ui.declarative.DesignException; @@ -5305,6 +5306,11 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, * properties in the desired column order */ public void setColumns(Object... propertyIds) { + if (SharedUtil.containsDuplicates(propertyIds)) { + throw new IllegalArgumentException( + "The propertyIds array contains duplicates: " + + SharedUtil.getDuplicates(propertyIds)); + } Set<?> removePids = new HashSet<Object>(columns.keySet()); removePids.removeAll(Arrays.asList(propertyIds)); for (Object removePid : removePids) { @@ -5327,6 +5333,11 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, * properties in the order columns should be */ public void setColumnOrder(Object... propertyIds) { + if (SharedUtil.containsDuplicates(propertyIds)) { + throw new IllegalArgumentException( + "The propertyIds array contains duplicates: " + + SharedUtil.getDuplicates(propertyIds)); + } List<String> columnOrder = new ArrayList<String>(); for (Object propertyId : propertyIds) { if (columns.containsKey(propertyId)) { diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridColumnsTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridColumnsTest.java index bf321f7ee9..24bd8b7f2a 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridColumnsTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridColumnsTest.java @@ -410,4 +410,22 @@ public class GridColumnsTest { assertThat(firstColumn.getHeaderCaption(), is("Column0")); } + + @Test(expected = IllegalStateException.class) + public void addColumnManyTimes() { + grid.removeAllColumns(); + grid.addColumn("column0"); + grid.addColumn("column0"); + } + + @Test(expected = IllegalArgumentException.class) + public void setColumnDuplicates() { + grid.removeAllColumns(); + grid.setColumns("column0", "column0"); + } + + @Test(expected = IllegalArgumentException.class) + public void setColumnOrderDuplicates() { + grid.setColumnOrder("column0", "column0"); + } } |