diff options
author | Leif Åstrand <leif@vaadin.com> | 2015-06-19 15:34:29 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-12-02 11:37:37 +0000 |
commit | 3cf57002b11ad400b8d4a33de1104b68a37e681a (patch) | |
tree | f01e0d9c88b7baaaacb31a1038a99840b805b627 /server/src/com/vaadin/ui/ConnectorTracker.java | |
parent | 907e689a418f04013a58428e687ebc5132b0f45d (diff) | |
download | vaadin-framework-3cf57002b11ad400b8d4a33de1104b68a37e681a.tar.gz vaadin-framework-3cf57002b11ad400b8d4a33de1104b68a37e681a.zip |
Detect hierarchy changes not sent to the client (#18317)
Change-Id: I77b420738738a42ff50e2a509e4ac4072b1b6e1f
Diffstat (limited to 'server/src/com/vaadin/ui/ConnectorTracker.java')
-rw-r--r-- | server/src/com/vaadin/ui/ConnectorTracker.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index 84454f9126..a060702319 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -37,6 +37,9 @@ import com.vaadin.server.DragAndDropService; import com.vaadin.server.GlobalResourceHandler; import com.vaadin.server.LegacyCommunicationManager; import com.vaadin.server.StreamVariable; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinService; +import com.vaadin.server.communication.ConnectorHierarchyWriter; import elemental.json.Json; import elemental.json.JsonException; @@ -326,6 +329,13 @@ public class ConnectorTracker implements Serializable { .isConnectorVisibleToClient(connector)) { uninitializedConnectors.add(connector); diffStates.remove(connector); + + assert isRemovalSentToClient(connector) : "Connector " + + connector + + " (id = " + + connector.getConnectorId() + + ") is no longer visible to the client, but no corresponding hierarchy change is being sent."; + if (getLogger().isLoggable(Level.FINE)) { getLogger() .log(Level.FINE, @@ -338,6 +348,48 @@ public class ConnectorTracker implements Serializable { cleanStreamVariables(); } + private boolean isRemovalSentToClient(ClientConnector connector) { + VaadinRequest request = VaadinService.getCurrentRequest(); + if (request == null) { + // Probably run from a unit test without normal request handling + return true; + } + + String attributeName = ConnectorHierarchyWriter.class.getName() + + ".hierarchyInfo"; + Object hierarchyInfoObj = request.getAttribute(attributeName); + if (hierarchyInfoObj instanceof JsonObject) { + JsonObject hierachyInfo = (JsonObject) hierarchyInfoObj; + + ClientConnector firstVisibleParent = findFirstVisibleParent(connector); + if (firstVisibleParent == null) { + // Connector is detached, not our business + return true; + } + + if (!hierachyInfo.hasKey(firstVisibleParent.getConnectorId())) { + return false; + } + } else { + getLogger().warning( + "Request attribute " + attributeName + + " is not a JsonObject"); + } + + return true; + } + + private ClientConnector findFirstVisibleParent(ClientConnector connector) { + while (connector != null) { + connector = connector.getParent(); + if (LegacyCommunicationManager + .isConnectorVisibleToClient(connector)) { + return connector; + } + } + return null; + } + private void removeUnregisteredConnectors() { GlobalResourceHandler globalResourceHandler = uI.getSession() .getGlobalResourceHandler(false); |