[jdom-interest] BETA8 bug
Mike Viens
Mike at Viens.com
Wed Mar 20 21:06:14 PST 2002
// masterChildren is populated with elements from a different Document
// BETA8 bug?
// example: when masterChildren has 4 elements, only two are ever
processed
// the list (masterChildren) is somehow being modified within the for
loop
// when the resource.detach() method is called - this works in BETA7
for (int j = 0; j < masterChildren.size(); j++)
{
Element resource = (Element)masterChildren.get(j);
// this line causes items in the list to be removed!
entity.addContent(resource.detach());
}
// solution 1 - to fix it in beta 8
Element entity = ........
Vector newChildren = new Vector();
for (int j = 0; j < masterChildren.size(); j++)
{
Element resource = (Element)masterChildren.get(j);
newChildren.add(resource);
}
for (int j = 0; j < newChildren.size(); j++)
{
Element resource = (Element)newChildren.get(j);
entity.addContent(resource.detach());
System.out.println("finished child: " + j + " - total: " +
newChildren.size());
}
// solution 2 - this also works
// change this line:
// for (int j = 0; j < masterChildren.size(); j++)
// to this:
// for (int j = 0; j < masterChildren.size(); )
More information about the jdom-interest
mailing list