aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-10-19 14:43:06 +0300
committerTeemu Suo-Anttila <teemusa@vaadin.com>2015-10-26 14:01:41 +0000
commitf5e2275e70a42817c4786657c385f8213ec365ee (patch)
treeae1bcf0ef1c40786b91c7253ff43e04d6268ed69
parentce161ac530bb9122e7a9c09d48b8f27218a8940b (diff)
downloadvaadin-framework-f5e2275e70a42817c4786657c385f8213ec365ee.tar.gz
vaadin-framework-f5e2275e70a42817c4786657c385f8213ec365ee.zip
Fix Grid NPE when deselecting already removed row (#19152)
Change-Id: I1361c8099e9f4a95e991f4937a406c5e4db67027
-rw-r--r--server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java16
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java13
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java14
3 files changed, 38 insertions, 5 deletions
diff --git a/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java b/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
index e3c48f1ec0..fed31646f4 100644
--- a/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
+++ b/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
@@ -367,15 +367,17 @@ public class RpcDataProviderExtension extends AbstractExtension {
for (int i = 0; i < newRange.length() && i + diff < itemIds.size(); ++i) {
Object itemId = itemIds.get(i + diff);
- rows.set(i, getRowData(getGrid().getColumns(), itemId));
+ Item item = container.getItem(itemId);
+
+ rows.set(i, getRowData(getGrid().getColumns(), itemId, item));
}
rpc.setRowData(firstRowToPush, rows);
activeItemHandler.addActiveItems(itemIds);
}
- private JsonObject getRowData(Collection<Column> columns, Object itemId) {
- Item item = container.getItem(itemId);
+ private JsonObject getRowData(Collection<Column> columns, Object itemId,
+ Item item) {
final JsonObject rowObject = Json.createObject();
for (DataGenerator dg : dataGenerators) {
@@ -497,12 +499,16 @@ public class RpcDataProviderExtension extends AbstractExtension {
return;
}
+ List<Column> columns = getGrid().getColumns();
JsonArray rowData = Json.createArray();
int i = 0;
for (Object itemId : itemIds) {
if (activeItemHandler.getActiveItemIds().contains(itemId)) {
- JsonObject row = getRowData(getGrid().getColumns(), itemId);
- rowData.set(i++, row);
+ Item item = container.getItem(itemId);
+ if (item != null) {
+ JsonObject row = getRowData(columns, itemId, item);
+ rowData.set(i++, row);
+ }
}
}
rpc.updateRowData(rowData);
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
index 94ee3ef348..777f5f6775 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -1396,6 +1396,19 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
ds.removeAllItems();
}
}, null);
+
+ createClickAction("Remove selected rows", "Body rows",
+ new Command<Grid, String>() {
+ @Override
+ public void execute(Grid c, String value, Object data) {
+ // Usually you'd deselect all the rows before removing
+ // them. It is done this way to test for #19152
+ for (Object itemId : c.getSelectedRows()) {
+ ds.removeItem(itemId);
+ }
+ c.select(null);
+ }
+ }, null);
}
protected void createEditorActions() {
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
index 8bf8639d76..44a632bc49 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
@@ -382,6 +382,20 @@ public class GridSelectionTest extends GridBasicFeaturesTest {
selectAll.isSelected());
}
+ @Test
+ public void testRemoveSelectedRow() {
+ openTestURL();
+
+ setSelectionModelSingle();
+ getGridElement().getCell(0, 0).click();
+
+ selectMenuPath("Component", "Body rows", "Remove selected rows");
+
+ assertFalse(
+ "Unexpected NullPointerException when removing selected rows",
+ logContainsText("Exception occured, java.lang.NullPointerException: null"));
+ }
+
private void waitUntilCheckBoxValue(final WebElement checkBoxElememnt,
final boolean expectedValue) {
waitUntil(new ExpectedCondition<Boolean>() {