[jdom-interest] java.util.ConcurrentModificationException

Phil Weighill-Smith phil.weighill-smith at volantis.com
Thu Jun 9 14:37:41 PDT 2005


I'd use an XPath expression to locate all the items I want to remove then remove them using something like Element#detach.

	-----Original Message----- 
	From: Bradley S. Huffman [mailto:hip at a.cs.okstate.edu] 
	Sent: Thu 09/06/2005 15:42 
	To: X.P.Pratibha :-) 
	Cc: jdom-interest at jdom.org 
	Subject: Re: [jdom-interest] java.util.ConcurrentModificationException 
	
	

	I'm see you have two iterators, listxpp and listxpp2, that you are using
	at the same time. I assume they have the same backing list.  The problem
	is a call to hasNext() on the first that returns true is giving a guarantee
	that a corresponding call to next() will return a valid object. In general
	allowing two iterator to modify the same backing list at the same time, or
	even one to modify while the other just transverses, could break this
	guarantee. So most java iterators don't allow it.
	
	Brad
	
	"X.P.Pratibha :-)" writes:
	
	> Hi all,
	>          I am having a ListIterator to traverse my JDOM. When I find a
	> list of my interest I am removing it using remove()...Its throwing
	> ConcurrentModificationException..Any thoughts will be of great help.
	> Please tell me whats going wrong???
	>
	> while(listxpp.hasNext())
	>                 {
	>                    int removecount=0;
	>                     Element FWnode = ((Element)
	> listxpp.next()).getChild("FirewallRule");
	>                     String ID =FWnode.getAttributeValue("id");       
	>
	>                       while(listxpp2.hasNext())
	>                       {
	>                       Element FWnode2 = ((Element) listxpp2.next()).getChild(
	> "FirewallRule");
	>                       String ID2 = FWnode2.getAttributeValue("id");
	>                      
	>                        if(ID.equals(ID2))
	>                        {
	>                       removecount++;
	>                       if(removecount>1)
	>                       {
	>                              
	>
	>                                 listxpp2.remove();
	>                                               }
	>                                                }
	>                             }
	>              
	>                             while(listxpp2.hasPrevious()){
	>                             Element PWnode = ((Element)
	> listxpp2.previous()).getChild("FirewallRule");
	>                                 }
	>             }
	> _______________________________________________
	> To control your jdom-interest membership:
	> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
	
	




More information about the jdom-interest mailing list