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

rolf.lear at algorithmics.com rolf.lear at algorithmics.com
Wed Oct 17 10:07:36 PDT 2007

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 code.

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 org.jdom.test.cases.TestFilterList
    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() + "_x"));
                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, i.previous());
            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 interest
> 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ContentList.java
Type: application/octet-stream
Size: 32314 bytes
Desc: ContentList.java
Url : http://www.jdom.org/pipermail/jdom-interest/attachments/20071017/f7759b10/ContentList.obj

More information about the jdom-interest mailing list