Author: markt
Date: Thu Feb 24 17:25:38 2011
New Revision: 1074225

URL: http://svn.apache.org/viewvc?rev=1074225&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50826
Avoid IAE when Tomcat instance is destroyed without every being started.
Add a test case for this.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1074225&r1=1074224&r2=1074225&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Thu Feb 24 
17:25:38 2011
@@ -5486,11 +5486,15 @@ public class StandardContext extends Con
             ((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();

Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java?rev=1074225&r1=1074224&r2=1074225&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java Thu Feb 24 
17:25:38 2011
@@ -326,4 +326,21 @@ public class TestTomcat extends TomcatBa
         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);
+    }
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1074225&r1=1074224&r2=1074225&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Feb 24 17:25:38 2011
@@ -133,7 +133,7 @@
       <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)
@@ -142,6 +142,11 @@
         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">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to