[jdom-interest] IllegalAddException in sort.

Ken Rune Helland kenh at csc.no
Tue May 28 07:37:41 PDT 2002


> I've just switched my application from b7 to b8 and am getting an
> IllegalAddException when calling Collections.sort() on a List returned
> from getChildren(String).
> 
> As the sort tries to rearrange the contents it calls
> ContentList.add(int,Element) which sees that an Element is being added
> that already has a parent. It doesn't notice that the new parent is the
> same as the current one. Would it be reasonable to add the 'same
> parent' test to the add() method? It works for me.
> 
> ContentList:
> protected void add(int index, Element element) {
>     if (element.getParent() != null && element.getParent() != parent) {
>         throw new IllegalAddException(
>             "The element already has an existing parent \""
> +element.getParent().getQualifiedName() + \"");
>     }
> 
> Ed Hurst-Frost

I think this is to weak because it allows the same element to be in the
content list of a parent multiple times. Then you cannot trust
that changing one child of an Element won't change another.


KenR





More information about the jdom-interest mailing list