From 07831bdd400236305028514aab1ade1f61e4903e Mon Sep 17 00:00:00 2001 From: markt Date: Thu, 24 Feb 2011 17:03:27 +0000 Subject: [PATCH] Don't start NamingResources multiple times git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1074215 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/core/StandardContext.java | 46 ++++++++++++++-------- webapps/docs/changelog.xml | 4 ++ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 9502068e5..b16bde713 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -1952,24 +1952,36 @@ public class StandardContext extends ContainerBase support.firePropertyChange("namingResources", oldNamingResources, this.namingResources); - // If set from server.xml, getObjectKeyPropertiesNameOnly() will - // trigger an NPE. Initial registration takes place on INIT. - if (getState() != LifecycleState.NEW) { - if (oldNamingResources != null) { - try { - oldNamingResources.stop(); - oldNamingResources.destroy(); - } catch (LifecycleException e) { - log.warn("standardContext.namingResource.destroy.fail", e); - } + if (getState() == LifecycleState.NEW || + getState() == LifecycleState.INITIALIZING || + getState() == LifecycleState.INITIALIZED) { + // NEW will occur if Context is defined in server.xml + // At this point getObjectKeyPropertiesNameOnly() will trigger an + // NPE. + // INITIALIZED will occur if the Context is defined in a context.xml + // file + // If started now, a second start will be attempted when the context + // starts + + // In both cases, return and let context init the namingResources + // when it starts + return; + } + + if (oldNamingResources != null) { + try { + oldNamingResources.stop(); + oldNamingResources.destroy(); + } catch (LifecycleException e) { + log.warn("standardContext.namingResource.destroy.fail", e); } - if (namingResources != null) { - try { - namingResources.init(); - namingResources.start(); - } catch (LifecycleException e) { - log.warn("standardContext.namingResource.init.fail", e); - } + } + if (namingResources != null) { + try { + namingResources.init(); + namingResources.start(); + } catch (LifecycleException e) { + log.warn("standardContext.namingResource.init.fail", e); } } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index a17ac9be2..8644ad3e8 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -138,6 +138,10 @@ of whether or not they provide a session token with their requests. (markt) + + Don't attempt to start NamingResources for Contexts multiple times. + (markt) + -- 2.11.0