[jdom-interest] PartialList not conforming List interface (using JDK 1.1collections)

Jason Hunter jhunter at acm.org
Fri Jul 7 19:17:57 PDT 2000


> So the bug seems to be in Suns code. Has anybody experienced this before.
> I heard that the com.sun.java.util.collections.LinkedList package is
> basically identical to the java.util.LinkedList JDK2 package. Then the bug
> must be there too.
> 
> For now I have made this fix to PartialList:
> 
>     public void add(int index, Object current) {
>         if (index == backingList.size())
>                 backingList.add(current);
>         else
>                 backingList.add(backingList.indexOf(get(index)), current);
>         ...

It's not a bug in Sun's code, it's a special case that adding to
"length" means to add to the end, but the code we had always expected
the index to refer to an existing object.  I changed it as follows (fix
is in CVS).

    public void add(int index, Object current) {
        if (index == size()) {
            // Adding to "length" spot is special case meaning to our
end
            addLast(current);
        }
        else {
            backingList.add(backingList.indexOf(get(index)), current);

            if (current instanceof Element) {
                ((Element)current).setParent(parent);  // null is OK
            }
            if (parent != null) {
                parent.clearContentCache();
            }
            super.add(index, current);
        }
    }

-jh-



More information about the jdom-interest mailing list