Bug 34164

Summary: context attributes not available when servlet's destroy() is called
Product: Tomcat 5 Reporter: Marc Guillemot <mguillemot>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED DUPLICATE    
Severity: blocker    
Priority: P2    
Version: 5.5.7   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Marc Guillemot 2005-03-24 14:37:36 UTC
In Tomcat 5.5.7, the context attributes seem to have been removed before the
method destroy() of the loaded servlets is called. This is not the case with
Tomcat 5.0.28 and I guess that it is wrong because Struts for instance relies on
it to destroy its modules (in
org.apache.struts.action.ActionServlet#destroyModules).

In the case of struts, this causes the plugins not to be notified that they are
destroyed what is against their expected behavior.

A simple servlet illustrates the problem:

public class TestServlet extends HttpServlet
{
  public void init() throws ServletException
  {
    log("In init TestServlet");
    getServletContext().setAttribute("test", "test");
    log("Attribute test: " + getServletContext().getAttribute("test"));
  }

  public void destroy()
  {
    log("In destroy TestServlet");
    log("Attribute test: " + getServletContext().getAttribute("test"));
    super.destroy();
  }
}

Configured with:
  <servlet>
    <servlet-name>test</servlet-name>
    <description>Custom test</description>
    <servlet-class>de.internetzky.test.TestServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
	

  <servlet-mapping>
    <servlet-name>test</servlet-name>
    <url-pattern>/foo/*</url-pattern>
  </servlet-mapping>

Gives following output in Tomcat 5.5.7:

INFO main org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test]
- test: In init TestServlet
 INFO main org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test]
- test: Attribute test: test

INFO http-8080-Processor24
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test] - test: In
destroy TestServlet
 INFO http-8080-Processor24
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test] - test:
Attribute test: null

but in Tomcat 5.0.28:
StandardContext[/test]test: In init TestServlet
StandardContext[/test]test: Attribute test: test

StandardContext[/test]test: In destroy TestServlet
StandardContext[/test]test: Attribute test: test
Comment 1 Remy Maucherat 2005-03-24 14:41:24 UTC

*** This bug has been marked as a duplicate of 33463 ***