diff options
author | Artur Signell <artur@vaadin.com> | 2016-10-12 21:59:08 +0300 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2016-12-09 09:39:00 +0200 |
commit | 76447b941ac64d5f1ad7bbf12555c3b73db23285 (patch) | |
tree | 555168174da9ce25fd05a1968bc35eb48452b987 /compatibility-server | |
parent | c94312a0f8a2c4afc019da16092eabad92ab7f2b (diff) | |
download | vaadin-framework-76447b941ac64d5f1ad7bbf12555c3b73db23285.tar.gz vaadin-framework-76447b941ac64d5f1ad7bbf12555c3b73db23285.zip |
Check for duplicate property ids when setting Grid columns or column order (#20386)
Change-Id: I76be83642f0e56e55b0c0e502ac6769de1ee8af0
Diffstat (limited to 'compatibility-server')
-rw-r--r-- | compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java | 10 | ||||
-rw-r--r-- | compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridColumnsTest.java | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java index e47294d440..6c811d070e 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java @@ -5367,6 +5367,11 @@ public class Grid extends AbstractComponent * 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<>(columns.keySet()); removePids.removeAll(Arrays.asList(propertyIds)); for (Object removePid : removePids) { @@ -5389,6 +5394,11 @@ public class Grid extends AbstractComponent * 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<>(); for (Object propertyId : propertyIds) { if (columns.containsKey(propertyId)) { diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridColumnsTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridColumnsTest.java index a0b2dc54bd..48d6baeaf6 100644 --- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridColumnsTest.java +++ b/compatibility-server/src/test/java/com/vaadin/v7/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"); + } } |