From e191abb0da9e4660e925991490e967c178380aef Mon Sep 17 00:00:00 2001 From: Henrik Paul Date: Wed, 25 Mar 2015 18:04:45 +0200 Subject: Fixed some faulty asserts in Grid's detail row creation (#17293) Change-Id: I8e9998524c02ca1e2f9d3391fa27bacc53655c7f --- .../com/vaadin/data/RpcDataProviderExtension.java | 36 ++++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'server/src/com/vaadin/data/RpcDataProviderExtension.java') diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index 217b2fe392..e645ec60f7 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -663,8 +663,10 @@ public class RpcDataProviderExtension extends AbstractExtension { assert itemId != null : "itemId was null"; Integer newRowIndex = Integer.valueOf(rowIndex); - assert !visibleDetailsComponents.containsKey(itemId) : "itemId " - + "already has a component. Should be destroyed first."; + if (visibleDetailsComponents.containsKey(itemId)) { + // Don't overwrite existing components + return; + } RowReference rowReference = new RowReference(grid); rowReference.set(itemId); @@ -695,14 +697,8 @@ public class RpcDataProviderExtension extends AbstractExtension { + "itemId is empty even though we just created a " + "component for it (" + itemId + ")"; } else { - assert !emptyDetails.containsKey(itemId) : "Bookkeeping has " - + "already itemId marked as empty (itemId: " + itemId - + ", old index: " + emptyDetails.get(itemId) - + ", new index: " + newRowIndex + ")"; - assert !emptyDetails.containsValue(newRowIndex) : "Bookkeeping" - + " already had another itemId for this empty index " - + "(index: " + newRowIndex + ", new itemId: " + itemId - + ")"; + assert assertItemIdHasNotMovedAndNothingIsOverwritten(itemId, + newRowIndex); emptyDetails.put(itemId, newRowIndex); } @@ -712,6 +708,26 @@ public class RpcDataProviderExtension extends AbstractExtension { */ } + private boolean assertItemIdHasNotMovedAndNothingIsOverwritten( + Object itemId, Integer newRowIndex) { + + Integer oldRowIndex = emptyDetails.get(itemId); + if (!SharedUtil.equals(oldRowIndex, newRowIndex)) { + + assert !emptyDetails.containsKey(itemId) : "Unexpected " + + "change of empty details row index for itemId " + + itemId + " from " + oldRowIndex + " to " + + newRowIndex; + + assert !emptyDetails.containsValue(newRowIndex) : "Bookkeeping" + + " already had another itemId for this empty index " + + "(index: " + newRowIndex + ", new itemId: " + itemId + + ")"; + } + + return true; + } + /** * Destroys correctly a details component, by the request of the client * side. -- cgit v1.2.3