PortletContextManager.remove(InternalPortletContext) fails

Details

Description

The destroy() method of the PortletServlet throws an exception when shutting down the container:

ERROR [ContainerBackgroundProcessor[StandardEngine[Catalina]]] [localhost].[/uP3] Mar/05 14:44:41.832 - Servlet GenericXsltPortlet threw unload() exception
javax.servlet.ServletException: Servlet.destroy() for servlet GenericXsltPortlet threw exception
at org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1339)
at org.apache.catalina.core.StandardWrapper.stop(StandardWrapper.java:1654)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4345)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1081)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1187)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:292)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1305)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1569)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1558)
at java.lang.Thread.run(Thread.java:595)

Tracing the code execution this is tracked to the PortletContextManager.remove(InternalPortletContext) call in which a Map keySet Iterator is used but remove() is called on the Map. Instead of calling remove() on the Map it should be called on the Iterator in use to prevent the ConcurrentModificationException.