[jdom-interest] Bug when iterating in reverse order over FilteredList

Vadim Strizhevsky Vadim.Strizhevsky at morganstanley.com
Wed Jul 23 13:36:53 PDT 2003


Hi,

I've hit what looks like a bug in JDOM b9 when iterating over children
in reverse order if there's a Text node at the end of the content list.
So for example if you have one of the following messages:

<root><e/>text</root> 

or

<root>text</root>

the following code will fail with CastException.

List children = rootElement.getChildren();
for (ListIterator iter =
children.listIterator(children.size());iter.hasPrevious();)
{
   Element element = (Element)iter.previous();
}


This is an extract from a larger code. Let me know if you need a fully
working test case. I think this bug is because the initial hasPrevious()
call does not adjust the cursor, while the constructor always adjust the
cursor forward only. I.e. it seems like the constructor of
ContentList.FilterListIterator assumes that iteration will always be
forward only. 

Thanks,
Vadim



More information about the jdom-interest mailing list