[jdom-interest] Maybe a bug report related to the "detach" method...

Joey Gibson joey at joeygibson.com
Fri Apr 12 06:07:15 PDT 2002

On Thu, 11 Apr 2002 10:22:19 +0100, Carlos Barroso
<est-c-barroso at ptinovacao.pt> wrote:

||| Exception in thread "main" java.util.ConcurrentModificationException
||| 	at
||| org.jdom.ConcurrentList$FilterListIterator.checkConcurrentModification( ...
||| )
||| 	at org.jdom.ContentList$FilterListIterator.hasNext( ... )
||| 	at JDOMDemo.main(JDOMDemo.java:25)

I saw this same problem. The j.u.CME is because you are removing something
from the collection while you are iterating it. In my case I had an XML
document that had several <Ticket> elements in it that were not nested
inside a <Tickets> element and I wanted to restructure it to have the
<Tickets> collection element. Here's my solution:

List tickets = root.getChildren("Ticket");
for (Iterator i = tickets.iterator(); i.hasNext(); ) 
	ticket = (Element) i.next();

This works because I am removing the Element from the collection using the
ITERATOR's remove, which is the only allowed method of modifying the
collection while iterating it. Once I put this code in, I was able to
detach the relevant node from the tree and move it into a new node, which
is the ticketCol reference.

-- Blue canary in the outlet by the lightswitch,
--  who watches over you...

More information about the jdom-interest mailing list