]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix IndexOutOfBoundsException when adding columns in Grid (#12095)
authorTatu Lund <tatu@vaadin.com>
Fri, 4 Sep 2020 10:35:13 +0000 (13:35 +0300)
committerGitHub <noreply@github.com>
Fri, 4 Sep 2020 10:35:13 +0000 (13:35 +0300)
There is regression in Vaadin 7.7.16 and later, which is due patch  https://github.com/vaadin/framework/commit/eafd44672650e076fc4a43362e11b47ffb0dbff1 that can lead to IndexOutOfBoundsException when there is hidden columns while adding new columns, which is similiar issue than earlier reported in https://github.com/vaadin/framework/issues/6784. Essentially the performance improvement patch overwrite some of the fix logic of https://github.com/vaadin/framework/commit/84533057435a99b0d0dfa9ea791de81921c1e260 This fix bring overwriten escalator index compensation back.

client/src/main/java/com/vaadin/client/widgets/Grid.java

index 7ef61eff5b13aef34000589fcefc77e8a2edd6ba..5be104fe5066db42d9b95cb18f4b746d8fcc8b40 100755 (executable)
@@ -6540,8 +6540,14 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
             }
         }
         if (visibleNewColumns > 0) {
+            int escalatorIndex = index;
+            for (int existingColumn = 0; existingColumn < index; existingColumn++) {
+                if (getColumn(existingColumn).isHidden()) {
+                    escalatorIndex--;
+                }
+            }
             final ColumnConfiguration columnConfiguration = this.escalator.getColumnConfiguration();
-            columnConfiguration.insertColumns(index, visibleNewColumns);
+            columnConfiguration.insertColumns(escalatorIndex, visibleNewColumns);
         }
 
         for (final Column<?, T> column : columnCollection) {