[jdom-interest] Pb with ConcurrentModificationException

Pellat, Dominique dominique.pellat at eds.com
Fri Jul 4 06:00:51 PDT 2003


Your guess was exact ! With attr.detach(), I aimed to detach the parent of
the attributes and elements. i.remove() makes the same thing while staying
in the context iterator. Thanks a lot. I can use JDOMb9 again.
 
Dominique

-----Message d'origine-----
De : Rolf Lear [mailto:rlear at algorithmics.com]
Envoyé : vendredi 4 juillet 2003 13:04
À : 'Pellat, Dominique'
Cc : 'jdom-interest at jdom.org'
Objet : RE: [jdom-interest] Pb with ConcurrentModificationException



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
<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
<http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourho
st.com>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030704/e2b36305/attachment.htm


More information about the jdom-interest mailing list