• Post Reply Bookmark Topic Watch Topic
  • New Topic

ConcurrentModificationException  RSS feed

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I've been running this app for a long time, and now this funny error happens. What has changed recently... for the first time, I'm running it on Tomcat 4.0.1 on a Solaris box. The same code does not throw exceptions on iPlanet, or on Tomcat 3.2.1 on Windows.
Here's the javadoc: Here is the code inside killSession, which I think is the cause?Originally, I had several session.removeAttribute("") statements, but it got tedious to add or remove these lines as I developed my app.
But it looks like Sessions in Tomcat4.0.1 are implemented as a Collection, and I'm making a modification to it (removing items) as i'm iterating over it? But I thought I was iterating over the enumeration, and not the original object. Should I be looking somewhere else?

And p.s. - The error does not always happen. ie: There are other cases where killSession() is called, and no error occurs.

[This message has been edited by Mike Curwen (edited October 29, 2001).]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems to be a bug in your code that was there all along and is now flagged up as such.
The exception is probably caused by a shift from a "native" Enumeration to one backed by an Iterator. Iterators are fail-fast: any modification of the collection (except those made through the Iterator itself) will cause a ConcurrentModificationException if you continue to use the iterator. But make no mistake, enumerations cannot handle concurrent modifications either. The difference is that an Enumeration is not fail-fast; concurrent modification of the underlying collection may silently lead to erratic behaviour.
You could put the attributes you need to delete in a temporary ArrayList, then go through that list and zap them.
- Peter
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter, that was the fix I was thinking of.

Seems a shame to loop over an enumeration and then need to loop over the arraylist I built up in the first loop.

 
raj sekhar
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure I completely understood the problem here.Can anyone of you let me know in little more detail.Thanks...! And I was wondering why iPlanet or the earlier version of Tomcat did not raise a flag !
Thanks
Raj
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raj, do you have a similar problem? otherwise, if you completely understand the problem, what more detail do you need?

replacing the loop with individual removeAttribute() calls has eliminated the error.

It is most likely, as Peter mentions, that both iPlanet (which uses old technology) and Tomcat (the older version) both used a session object that returned an enumeration of attributes that was Not backed by an Iterator. ie: It was a 'plain' Enumeration. Once I switched to catalina (note the single instance of the catalina on the second line of the stack trace...) then it blew up when I attempted to modified the backing collection of the iterator.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!