docs: @Override
      public void onApplicationEvent(HttpSessionDestroyedEvent event) {
          final HttpSession session = ((HttpSessionDestroyedEvent) event).getSession();
          @SuppressWarnings("unchecked")
          final Map<String, PortletSession> portletSessions =
                  (Map<String, PortletSession>) session.getAttribute(PORTLET_SESSIONS_MAP);
          if (portletSessions == null) {
              return;
          }
  
          /*
           * Since (at least) Tomcat 7.0.47, this method has the potential to
           * generate a StackOverflowError because PortletSession.invalidate()
           * will trigger another HttpSessionDestroyedEvent, which means this
           * method will be called again.  I don't know if this behavior is a bug
           * in Tomcat or Spring, if this behavior is entirely proper, or if the
           * reality somewhere in between.
           *
           * For the present, let's put a token in the HttpSession (which is
           * available from the event object) as soon as we start invalidating it.
           * We'll then ignore sessions that already have this token.
           */
          if (session.getAttribute(ALREADY_INVALIDATING_SESSION_ATTRIBUTE) != null) {
              // We're already invalidating;  don't do it again
              return;
          }
          session.setAttribute(ALREADY_INVALIDATING_SESSION_ATTRIBUTE, Boolean.TRUE);
  
          for (final Map.Entry<String, PortletSession> portletSessionEntry :
                  portletSessions.entrySet()) {
              final String contextPath = portletSessionEntry.getKey();
              final PortletSession portletSession = portletSessionEntry.getValue();
              try {
                  portletSession.invalidate();
              } catch (IllegalStateException e) {
                  this.logger.info(
                          "PortletSession with id '"
                                  + portletSession.getId()
                                  + "' for context '"
                                  + contextPath
                                  + "' has already been invalidated.");
              } catch (Exception e) {
                  this.logger.warn(
                          "Failed to invalidate PortletSession with id '"
                                  + portletSession.getId()
                                  + "' for context '"
                                  + contextPath
                                  + "'",
                          e);
              }
          }
      }