Bug 59449

Summary: org.apache.catalina.core.ContainerBase#removeChild remove order
Product: Tomcat 9 Reporter: Huxing Zhang <huxing.zhang>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 9.0.0.M4   
Target Milestone: -----   
Hardware: PC   
OS: Mac OS X 10.1   
Attachments: patch to implement the proposed behaviour.

Description Huxing Zhang 2016-05-10 06:02:59 UTC
Created attachment 33832 [details]
patch to implement the proposed behaviour.

Hi, 

In org.apache.catalina.core.ContainerBase#addChildInternal,  we have the following execution order:

1. put child to children
2. call child' start
3. fire ADD_CHILD_EVENT

However, in org.apache.catalina.core.ContainerBase#removeChild, the execution order is not in reverse order:

1. remove child from children
2. call child's stop
3. fire REMOVE_CHILD_EVENT
4. call child's destroy if necessary 

This may lead to some unexpected behaviour. e.g. One can deploy a web app while it is being undeployed.

Proposed execution order  in removeChild:

1. call child's stop
2. call child's destroy if necessary 
3. remove child from children
4. fire REMOVE_CHILD_EVENT
Comment 1 Mark Thomas 2016-05-10 08:50:30 UTC
Thanks for the report and the patch.

This has been fixed in the following versions:
- 9.0.x for 9.0.0.M5
- 8.5.x for 8.5.1
- 8.0.x for 8.0.34
- 7.0.x for 7.0.70
- 6.0.x for 6.0.46