[jdom-interest] Document setMixedContent bug

Dan Sojka dan_sojka at centegy.com
Mon Nov 27 18:13:10 PST 2000


There is a bug in the org.jdom.Document setMixedContent() method. The
result is always an empty Document because the parameter "content" List
is being cleared instead of the "content" List field declared in the
class.  The bug was found in latest 11/27/00 daily snapshot
jdom-src.zip.

 public Document setMixedContent(List content) {
        content.clear(); // <<< should be this.content.clear().
        rootElement = null;

        for (Iterator i = content.iterator(); i.hasNext(); ) {
            Object obj = i.next();
            if (obj instanceof Element) {
                addContent((Element)obj);
            }
            else if (obj instanceof Comment) {
                addContent((Comment)obj);
            }
            else if (obj instanceof ProcessingInstruction) {
                addContent((ProcessingInstruction)obj);
            }
            else {
                throw new IllegalAddException(
                    "A Document may contain only objects of type
Element, " +
                    "Comment, and ProcessingInstruction");
            }
        }

        return this;
    }




More information about the jdom-interest mailing list