[Pradip Bhat]: ConcurrentModificationException occurs when another or the current thread tries to manipulate the Collection when the current thread is iterationg the Collection . Not necessarily another thread. Could also be the same thread, as seen here.
It is surprising to see this exception occuring for Enumeration interface which is outside the Collection framework. It is surprising. But remember that Enumeration is just an interface - how is it implemented underneath? In this case it I'm guessing that
Tomcat's HttpSession may be using a HashMap or TreeMap internally to maintain the session attributes, and getAttributeNames() is returning an Enumeration which gives a view of the keySet(). Unfortunately this is a bad choice for Tomcat - the HttpSession API doesn't really offer a better way to remove attributes. They should have returned an enumeration containing a
copy of the attribute names, so this wouldn't be an issue. Oh well.
Pradip,
you should be able to work around this by copying the Enumeration to a separate List, then iterate through the List and removeAttribute() for each name.