<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2655.35">
<TITLE>RE: [jdom-interest] Pb with ConcurrentModificationException</TITLE>
</HEAD>
<BODY>
<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>
</BODY>
</HTML>