[jdom-interest] Pb with ConcurrentModificationException

Rolf Lear rlear at algorithmics.com
Fri Jul 4 04:04:02 PDT 2003


My guess is that it is breaking with the "attr.detach()"

Concurrent modification occurs if the list i modified outside the context of
the iterator.

you have an iterator on the attribute list with Iterator
i=attrsRootDataFile.iterator()

To remove items from an list when iterating over that list you have to use
the iterators remove method.

So, in your case, the for loop works the first time, detaching the
attribute, but the next time, when calling i.next(), it throws concurrent
modification.

This is solved by using i.remove() instead of attr.detach().

Rolf


-----Original Message-----
From: Pellat, Dominique [mailto:dominique.pellat at eds.com]
Sent: Friday, July 04, 2003 3:41 AM
To: 'jdom-interest at jdom.org'
Subject: [jdom-interest] Pb with ConcurrentModificationException


I found a pb in JDOMb9 about the checkForComodification() method in
AbstractList :

I first created an instance of Document:

            domDataFile = builder.build("FichierLocal.xml");
	and use XMLOutputter after.

I then send domDataFile to another method in order to get the attributes,
detach them and create a new Attribute List :

      Element racineDataFile = domDataFile.getRootElement();
      // liste des attributs de la racine :
      List attrsRootDataFile = racineDataFile.getAttributes();
      List attrsRootDataFileFree = new ArrayList();
      for (Iterator i=attrsRootDataFile.iterator(); i.hasNext(); ) {
Exception-->     	 Attribute attr = (Attribute)i.next();
		 System.out.println("DataFile/attr :"+attr.getName());
		 attr.detach();
		 attrsRootDataFileFree.add(attr);
      }

Then I get :
java.util.ConcurrentModificationException
 	at
java.util.AbstractList$Itr.checkForComodification(AbstractList.java:448)
 	at java.util.AbstractList$Itr.next(AbstractList.java:419)
 	at maquette.Access_Data.LectureDonnees(Access_Data.java:186)

When using JDOMb7 the problem did not appear. Do you have an idea (about the
modCount management in AbstractList class) ?


Dominique
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030704/0fb746f9/attachment.htm


More information about the jdom-interest mailing list