<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>RE: [jdom-interest] Pb with ConcurrentModificationException</TITLE>
<META content="MSHTML 5.00.3315.2870" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=717365412-04072003>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.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=717365412-04072003></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=717365412-04072003>Dominique</SPAN></FONT></DIV>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
<DIV align=left class=OutlookMessageHeader dir=ltr><FONT face=Tahoma
size=2>-----Message d'origine-----<BR><B>De :</B> Rolf Lear
[mailto:rlear@algorithmics.com]<BR><B>Envoyé :</B> vendredi 4 juillet
2003 13:04<BR><B>À :</B> 'Pellat, Dominique'<BR><B>Cc :</B>
'jdom-interest@jdom.org'<BR><B>Objet :</B> RE: [jdom-interest] Pb with
ConcurrentModificationException<BR><BR></DIV></FONT>
<P><FONT size=2>My guess is that it is breaking with the
"attr.detach()"</FONT> </P>
<P><FONT size=2>Concurrent modification occurs if the list i modified outside
the context of the iterator.</FONT> </P>
<P><FONT size=2>you have an iterator on the attribute list with Iterator
i=attrsRootDataFile.iterator()</FONT> </P>
<P><FONT size=2>To remove items from an list when iterating over that list you
have to use the iterators remove method.</FONT> </P>
<P><FONT size=2>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.</FONT></P>
<P><FONT size=2>This is solved by using i.remove() instead of
attr.detach().</FONT> </P>
<P><FONT size=2>Rolf</FONT> </P><BR>
<P><FONT size=2>-----Original Message-----</FONT> <BR><FONT size=2>From:
Pellat, Dominique [<A
href="mailto:dominique.pellat@eds.com">mailto:dominique.pellat@eds.com</A>]</FONT>
<BR><FONT size=2>Sent: Friday, July 04, 2003 3:41 AM</FONT> <BR><FONT
size=2>To: 'jdom-interest@jdom.org'</FONT> <BR><FONT size=2>Subject:
[jdom-interest] Pb with ConcurrentModificationException</FONT> </P><BR>
<P><FONT size=2>I found a pb in JDOMb9 about the checkForComodification()
method in</FONT> <BR><FONT size=2>AbstractList :</FONT> </P>
<P><FONT size=2>I first created an instance of Document:</FONT> </P>
<P><FONT
size=2>
domDataFile = builder.build("FichierLocal.xml");</FONT>
<BR> <FONT size=2>and use
XMLOutputter after.</FONT> </P>
<P><FONT size=2>I then send domDataFile to another method in order to get the
attributes,</FONT> <BR><FONT size=2>detach them and create a new Attribute
List :</FONT> </P>
<P><FONT size=2> Element racineDataFile =
domDataFile.getRootElement();</FONT> <BR><FONT
size=2> // liste des attributs de la racine
:</FONT> <BR><FONT size=2> List
attrsRootDataFile = racineDataFile.getAttributes();</FONT> <BR><FONT
size=2> List attrsRootDataFileFree = new
ArrayList();</FONT> <BR><FONT size=2> for
(Iterator i=attrsRootDataFile.iterator(); i.hasNext(); ) {</FONT> <BR><FONT
size=2>Exception-->
Attribute attr =
(Attribute)i.next();</FONT> <BR>
<FONT size=2>
System.out.println("DataFile/attr :"+attr.getName());</FONT>
<BR>
<FONT size=2>
attr.detach();</FONT> <BR>
<FONT size=2>
attrsRootDataFileFree.add(attr);</FONT> <BR><FONT
size=2> }</FONT> </P>
<P><FONT size=2>Then I get :</FONT> <BR><FONT
size=2>java.util.ConcurrentModificationException</FONT> <BR><FONT
size=2> at</FONT> <BR><FONT
size=2>java.util.AbstractList$Itr.checkForComodification(AbstractList.java:448)</FONT>
<BR><FONT size=2> at
java.util.AbstractList$Itr.next(AbstractList.java:419)</FONT> <BR><FONT
size=2> at
maquette.Access_Data.LectureDonnees(Access_Data.java:186)</FONT> </P>
<P><FONT size=2>When using JDOMb7 the problem did not appear. Do you have an
idea (about the</FONT> <BR><FONT size=2>modCount management in AbstractList
class) ?</FONT> </P><BR>
<P><FONT size=2>Dominique</FONT> <BR><FONT
size=2>_______________________________________________</FONT> <BR><FONT
size=2>To control your jdom-interest membership:</FONT> <BR><FONT size=2><A
href="http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com"
target=_blank>http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com</A></FONT>
</P></BLOCKQUOTE></BODY></HTML>