From: markt Date: Wed, 12 May 2010 10:24:00 +0000 (+0000) Subject: Fix remainder of https://issues.apache.org/bugzilla/show_bug.cgi?id=49181 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=23bd370ae18f34e6ceef531b34874af7d69518ff;p=tomcat7.0 Fix remainder of https://issues.apache.org/bugzilla/show_bug.cgi?id=49181 Add additional check to prevent adding Servlet context listeners once the calls to the Servlet Context listeners start git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@943432 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/ApplicationContext.java b/java/org/apache/catalina/core/ApplicationContext.java index 47b18b1e5..d901b1a19 100644 --- a/java/org/apache/catalina/core/ApplicationContext.java +++ b/java/org/apache/catalina/core/ApplicationContext.java @@ -184,6 +184,13 @@ public class ApplicationContext private Set defaultSessionTrackingModes = null; private Set supportedSessionTrackingModes = null; + /** + * Flag that indicates if a new {@link ServletContextListener} may be added + * to the application. Once the first {@link ServletContextListener} is + * called, not more may be added. + */ + private boolean newServletContextListenerAllowed = true; + // --------------------------------------------------------- Public Methods @@ -1275,8 +1282,8 @@ public class ApplicationContext } if (t instanceof HttpSessionListener - || t instanceof ServletContextListener) { - // TODO SERVLET3 - if ServletContextListener then also need to check caller? spec isn't clear + || (t instanceof ServletContextListener && + newServletContextListenerAllowed)) { context.addApplicationLifecycleListener(t); match = true; } @@ -1471,6 +1478,10 @@ public class ApplicationContext } + protected void setNewServletContextListenerAllowed(boolean allowed) { + this.newServletContextListenerAllowed = allowed; + } + // -------------------------------------------------------- Private Methods diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 9a0a6e29d..3869e0535 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -4266,6 +4266,10 @@ public class StandardContext extends ContainerBase if (getLogger().isDebugEnabled()) getLogger().debug("Sending application start events"); + // Ensure context is not null + getServletContext(); + context.setNewServletContextListenerAllowed(false); + Object instances[] = getApplicationLifecycleListeners(); if (instances == null) return (ok);