[jdom-interest] PartialList not conforming List interface (using JDK 1.1
collections)
Gabor Greif
gabor at no.netopia.com
Fri Jul 7 06:45:30 PDT 2000
PartialList l;
...
l.add(l.size(), "new");
will throw IndexOutOfBoundsException
But the spec says that this should only be thrown if (index < 0 || index >
size()).
Stepping into the method
public void add(int index, Object current) {
backingList.add(backingList.indexOf(get(index)), current); <<
throws
...
}
shows that the exception comes from the marked line. backingList is a
LinkedList, and that is defined in the JDK 1.1 collections jar in package
com.sun.java.util.collections.LinkedList.
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);
...
Gabor
More information about the jdom-interest
mailing list