Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50826
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 24 Feb 2011 17:25:38 +0000 (17:25 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 24 Feb 2011 17:25:38 +0000 (17:25 +0000)
Avoid IAE when Tomcat instance is destroyed without every being started.
Add a test case for this.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1074225 13f79535-47bb-0310-9956-ffa450edef68

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

index b16bde7..4291d39 100644 (file)
@@ -5486,11 +5486,15 @@ public class StandardContext extends ContainerBase
             ((Lifecycle) loader).destroy();
         }
 
-        // Send j2ee.object.deleted notification 
-        Notification notification = 
-            new Notification("j2ee.object.deleted", this.getObjectName(), 
-                             sequenceNumber.getAndIncrement());
-        broadcaster.sendNotification(notification);
+        // If in state NEW when destroy is called, the object name will never
+        // have been set so the notification can't be created
+        if (getObjectName() != null) { 
+            // Send j2ee.object.deleted notification 
+            Notification notification = 
+                new Notification("j2ee.object.deleted", this.getObjectName(), 
+                                 sequenceNumber.getAndIncrement());
+            broadcaster.sendNotification(notification);
+        }
 
         if (namingResources != null) {
             namingResources.destroy();
index 1366488..1d4ed23 100644 (file)
@@ -326,4 +326,21 @@ public class TestTomcat extends TomcatBaseTest {
         assertTrue(res.toString().contains("<?xml version=\"1.0\" "));
     }
 
+    public void testBug50826() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        String contextPath = "/examples";
+        
+        File appDir = new File(getBuildDirectory(), "webapps" + contextPath);
+        // app dir is relative to server home
+        tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
+
+        Exception e = null;
+        try {
+            tomcat.destroy();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            e = ex;
+        }
+        assertNull(e);
+    }
 }
index 8644ad3..2dad462 100644 (file)
       <add>
         Web crawlers can trigger the creation of many thousands of sessions as
         they crawl a site which may result in significant memory consumption.
-        Thw new Crawler Session Manager Valve ensures that crawlers are
+        The new Crawler Session Manager Valve ensures that crawlers are
         associated with a single session - just like normal users - regardless
         of whether or not they provide a session token with their requests.
         (markt)
         Don&apos;t attempt to start NamingResources for Contexts multiple times.
         (markt) 
       </fix>
+      <fix>
+        <bug>50826</bug>: Avoid <code>IllegalArgumentException</code> if an
+        embedded Tomcat instance that includes at least one Context is destroyed
+        without ever being started. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">