]> source.dussan.org Git - vaadin-framework.git/commitdiff
Throw exception from multiple columns with same identifier
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Wed, 19 Oct 2016 09:05:09 +0000 (12:05 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 19 Oct 2016 09:51:38 +0000 (09:51 +0000)
Change-Id: Ibb002cb862a7d0069ce4757e4c11482f6ae4d354

server/src/main/java/com/vaadin/ui/Grid.java
server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java

index a27130903e5f36244be4bbf0b7426422a746d4af..843db35e167262d551a6754f72cd0733ad6fc409 100644 (file)
@@ -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) {
index 7c4af0b5bf09ae5eb996b9283bbdc9cdfb37a1c5..eec20e2b9dd5b0bb99f96ca0a30808eaf4dad7d3 100644 (file)
@@ -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);
+    }
 }