diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-10-19 12:05:09 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-10-19 09:51:38 +0000 |
commit | 5fc90cda4c27402414fd31c1b87194968321a2fa (patch) | |
tree | 10b0746d1bf8255d86c424643d50061f897175a1 | |
parent | 8b2de181c37ee855608153fdff9a58474bf945cc (diff) | |
download | vaadin-framework-5fc90cda4c27402414fd31c1b87194968321a2fa.tar.gz vaadin-framework-5fc90cda4c27402414fd31c1b87194968321a2fa.zip |
Throw exception from multiple columns with same identifier
Change-Id: Ibb002cb862a7d0069ce4757e4c11482f6ae4d354
-rw-r--r-- | server/src/main/java/com/vaadin/ui/Grid.java | 13 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java | 5 |
2 files changed, 15 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index a27130903e..843db35e16 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -1635,14 +1635,19 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents { * the column value type * * @return the new column + * @throws IllegalArgumentException + * if the same identifier is used for multiple columns * * @see {@link AbstractRenderer} */ public <V> Column<T, V> addColumn(String identifier, Function<T, ? extends V> valueProvider, - AbstractRenderer<? super T, V> renderer) { - assert !columnKeys.containsKey(identifier) : "Duplicate identifier: " - + identifier; + AbstractRenderer<? super T, V> renderer) + throws IllegalArgumentException { + if (columnKeys.containsKey(identifier)) { + throw new IllegalArgumentException( + "Multiple columns with the same identifier: " + identifier); + } final Column<T, V> column = new Column<>( SharedUtil.camelCaseToHumanFriendly(identifier), valueProvider, @@ -1661,6 +1666,8 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents { * the value provider * * @return the new column + * @throws IllegalArgumentException + * if the same identifier is used for multiple columns */ public Column<T, String> addColumn(String identifier, Function<T, String> valueProvider) { diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java index 7c4af0b5bf..eec20e2b9d 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java @@ -74,4 +74,9 @@ public class GridTest { "Random Column Id", grid.getColumn("randomColumnId").getCaption()); } + + @Test(expected = IllegalArgumentException.class) + public void testGridMultipleColumnsWithSameIdentifier() { + grid.addColumn("foo", t -> t); + } } |