[jdom-interest] Element.getMixedContent.addAll(Collection) Element.getMixedContent.add(Element)(etc) add TWICE

Michael Skells mskells at aspirebanking.com
Thu Nov 16 02:17:08 PST 2000

PartailList ( returned by getMixedContent) is a subclass of LinkedList.
Many of the methods ( add, addAll, removeAll ... ) perform logic to
maintain the list ( locally held ( by the super class and in the backing
store, but the superclass calls back to the child to perform actions

PartialList.addAll(collection)  adds to the backing store and calls
LinkedList.addAll(Collection) to maintain the list, which calls
PartialList.addAll(int, Collection) the add the elements at the end,
which adds to the backing store AGAIN and calls
LinkedList.addAll(int, Collection) to maintain the list.

This style of coding in not safe as it would be legitimate for
LinkedList.addAll(int, Collection) to call add(int, Object) which would
add it a third time!!!

As the implementation of LinkedList is not part of its specification
then inheritance is not a safe mechanism to use for this type of
behavior, and I would strongly suggest that this gets rewritten to use



More information about the jdom-interest mailing list