[jdom-interest] Bug in ListIterator.add() method

rolf.lear at algorithmics.com rolf.lear at algorithmics.com
Thu Oct 25 08:10:55 PDT 2007

Hi Jason.

Is there any feedback on this? I don't like pestering you but it would
be very useful to have some idea of whether JDom is going to be patched
in some way to fix the bug (it is at least 2 years old now). 



-----Original Message-----
From: Rolf Lear 
Sent: Wednesday, October 17, 2007 1:08 PM
To: Rolf Lear; 'Bradley S. Huffman'; 'jhunter at servlets.com'
Cc: 'jdom-interest at jdom.org'
Subject: RE: [jdom-interest] Bug in ListIterator.add() method

Hi All.

I have run in to this bug (again), and notice that the fix for this bug
is not yet committed to CVS.

The logic in the existing ContentList.ListIterator class is pretty
complex (and broken), and it can be substantially simplified while at
the same time fixing the problems.

I submitted the patch to do this a number of times .... but the CVS repo
has moved on again, so, I have manually applied the patch to the latest
CVS, and here submit the full ContentList.java source. The only changes
are in the ListIterator subclass, which has been entirely rewritten.

In addition, I have run the tests that Christian Gruber proposed on 22
April 2005 by compiling JDom with java 1.3.1_20, and using his test

Finally, I have run the test suite over the 1.3.1_20 jar with the fix,
and it has passed 177 of 177 tests. I added an additional test that
illustrates the fixed bugs, making 178 tests. These tests all pass.

Here is the additional test I incorporated in
    public void test_TCM__ListIterator_listIterator_int3() {
        try {
            Element r = new Element("root");
            Document d = new Document().setRootElement(r);
            r.addContent(new Element("element").setText("1"));
            r.addContent(new Element("element").setText("2"));
            r.addContent(new Element("element").setText("3"));

            Element xxx = new Element("element").setText("xxx");
            Element yyy = new Element("element").setText("yyy");

            ListIterator i = r.getChildren("element").listIterator();
            while (i.hasNext()) {
                Element e = (Element) i.next();
                i.add(new Element("element").setText(e.getText() +
                i.add(new Element("element").setText(e.getText() +
"_y")); // bug1 - double add should work
            i.add(xxx); // bug2 - add at end of list....
            assertEquals("previous() is not recent add()", xxx,
            assertEquals("yyy not attached", r, yyy.getParent());
            assertFalse("xxx is still attached", xxx.isAncestor(r));
        } catch (OutOfMemoryError oom) {
            fail("ListIterator.add() caused OutOfMemory!");
        } catch (Exception e) {
            fail("Unable to complete ListIterator tests");

Finally, the ContentList source is attached.


-----Original Message-----
From: Rolf Lear 
Sent: Tuesday, October 11, 2005 5:41 PM
To: 'Bradley S. Huffman'; Rolf Lear
Cc: jdom-interest at jdom.org
Subject: RE: [jdom-interest] Bug in ListIterator.add() method

Just to bump this to the top of the list again.... is this code being
used by anyone ... it is not in CVS.


-----Original Message-----
From: Bradley S. Huffman [mailto:hip at a.cs.okstate.edu]
Sent: Tuesday, May 17, 2005 10:17 AM
To: Rolf Lear
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] Bug in ListIterator.add() method

Rolf Lear writes:

> Just to confirm the status of this patch .... and rejuvenate some
> in it.
> Has it been rejected?

No, it just seems everyone has been very, very busy. I know I have for
the last

This email and any files transmitted with it are confidential and proprietary to Algorithmics Incorporated and its affiliates ("Algorithmics"). If received in error, use is prohibited. Please destroy, and notify sender. Sender does not waive confidentiality or privilege. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. Algorithmics does not accept liability for any errors or omissions. Any commitment intended to bind Algorithmics must be reduced to writing and signed by an authorized signatory.

More information about the jdom-interest mailing list