]> source.dussan.org Git - vaadin-framework.git/commitdiff
Log informative message instead of failing with ClassCastException when polling an...
authorAnna Koskinen <Ansku@users.noreply.github.com>
Tue, 20 Oct 2020 11:10:48 +0000 (14:10 +0300)
committerGitHub <noreply@github.com>
Tue, 20 Oct 2020 11:10:48 +0000 (14:10 +0300)
https://github.com/vaadin/framework/issues/12113

Authored-by: Martin Vysny <martin@vysny.me>
server/src/main/java/com/vaadin/server/AbstractClientConnector.java

index fe167364650e825c4e6b91255b4c0df49ee3792c..1a167431053e2c8b93de1748dd2e95b732e41eff 100644 (file)
@@ -31,6 +31,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.WeakHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import com.vaadin.event.EventRouter;
 import com.vaadin.event.MethodEventSource;
@@ -50,6 +52,8 @@ import com.vaadin.util.ReflectTools;
 import elemental.json.JsonObject;
 import elemental.json.JsonValue;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * An abstract base class for ClientConnector implementations. This class
  * provides all the basic functionality required for connectors.
@@ -59,6 +63,11 @@ import elemental.json.JsonValue;
  */
 public abstract class AbstractClientConnector
         implements ClientConnector, MethodEventSource {
+
+    private static Logger getLogger() {
+        return Logger.getLogger(AbstractClientConnector.class.getName());
+    }
+
     /**
      * A map from client to server RPC interface class name to the RPC call
      * manager that handles incoming RPC calls for that interface.
@@ -669,11 +678,18 @@ public abstract class AbstractClientConnector
         VaadinSession session = getSession();
         session.lock();
         try {
-            ConnectorResource resource = (ConnectorResource) getResource(key);
+            Resource resource = getResource(key);
             if (resource == null) {
                 return false;
+            } else if (!(resource instanceof ConnectorResource)) {
+                response.sendError(HttpServletResponse.SC_NOT_FOUND,
+                        "Resource is no longer present");
+                getLogger().log(Level.INFO, "The resource '" + key + "' is a "
+                        + resource.getClass().getSimpleName()
+                        + " now; it is no longer a ConnectorResource and request could not be handled");
+                return true;
             }
-            stream = resource.getStream();
+            stream = ((ConnectorResource) resource).getStream();
         } finally {
             session.unlock();
         }