]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add sanity check to removeColumn in Grid server side (#16219)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Wed, 14 Jan 2015 13:41:16 +0000 (15:41 +0200)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 15 Jan 2015 13:15:12 +0000 (13:15 +0000)
Change-Id: I306442d93ccc488018065cee3b5c1a79aa8d6e34

server/src/com/vaadin/ui/Grid.java
server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java

index 175c326f1428105837e7899309b8624b50f24b8a..18d45b3b9f2fc6a8d2db8c82b4e9364ad3420dc3 100644 (file)
@@ -3116,8 +3116,16 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
      * 
      * @param propertyId
      *            The property id of column to be removed
+     * 
+     * @throws IllegalArgumentException
+     *             if there is no column for given property id in this grid
      */
-    public void removeColumn(Object propertyId) {
+    public void removeColumn(Object propertyId) throws IllegalArgumentException {
+        if (!columns.keySet().contains(propertyId)) {
+            throw new IllegalArgumentException(
+                    "There is no column for given property id " + propertyId);
+        }
+
         List<Column> removed = new ArrayList<Column>();
         removed.add(getColumn(propertyId));
         internalRemoveColumn(propertyId);
index 1204b1e39653517b7f67cfdb02dfb706c12f81a2..4501fc8e39f6efebd5e296c9ff93f3a41c7bfae0 100644 (file)
@@ -228,6 +228,11 @@ public class GridColumns {
         }
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void testRemoveColumnThatDoesNotExist() {
+        grid.removeColumn("banana phone");
+    }
+
     private GridColumnState getColumnState(Object propertyId) {
         String columnId = columnIdMapper.key(propertyId);
         for (GridColumnState columnState : state.columns) {