[jdom-commits] CVS update: jdom/src/java/org/jdom

jhunter at cvs.jdom.org jhunter at cvs.jdom.org
Tue Dec 5 00:21:15 PST 2000

Date:	Tuesday December 5, 2000 @ 8:21
Author:	jhunter

Update of /home/cvspublic/jdom/src/java/org/jdom
In directory www.nmemonix.com:/tmp/cvs-serv20850

Modified Files:
Log Message:
Added logic to prevent an elt from being added as a child or descendent
of itself.  Previously if you had elt One with a child Two, you could do
Two.addContent(One) and the API wouldn't detect a problem.  That is, until
output when you'd get into an infinite loop.  Now addContent() scans the 
ancestry of the elt getting the new child to make sure the child isn't 
in its ancestry.

This logic should be added to PartialList as well, as noted in TODO.txt.

This check does increase processing time for each add, but not too much 
because it's a scan up the tree and not an exhaustive search down.

This change was discussed in an old thread 'How to "crash" JDOM' and was 
sitting in the TODO.

Here's code to demonstrate the problem that was fixed.

import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

public class Tester3 {

  public static void main(String[] args) throws Exception {
    Element a = new Element("a");
    Element b = new Element("b");
    b.addContent(a); // bang!
    new XMLOutputter("  ", true).output(new Document(a), System.out);


File: Element.java     	Status: Up-to-date

   Working revision:	1.43	Tue Dec  5 08:21:15 2000
   Repository revision:	1.43	/home/cvspublic/jdom/src/java/org/jdom/Element.java,v

   Existing Tags:
	start                    	(revision:
	jdom                     	(branch: 1.1.1)

More information about the jdom-commits mailing list