Don't start NamingResources multiple times
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 24 Feb 2011 17:03:27 +0000 (17:03 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 24 Feb 2011 17:03:27 +0000 (17:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1074215 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/StandardContext.java
webapps/docs/changelog.xml

index 9502068..b16bde7 100644 (file)
@@ -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);
             }
         }
     }
index a17ac9b..8644ad3 100644 (file)
         of whether or not they provide a session token with their requests.
         (markt)
       </add>
+      <fix>
+        Don&apos;t attempt to start NamingResources for Contexts multiple times.
+        (markt) 
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">