[jdom-interest] ContentList instanceof stacks

Elliotte Rusty Harold elharo at metalab.unc.edu
Fri Apr 19 07:03:17 PDT 2002


The following code occurs in org.jdom.ContentList:

    public void add(int index, Object obj) {
        if (obj instanceof Element) {
            add(index, (Element) obj);
        }
        else if (obj instanceof Text) {
            add(index, (Text) obj);
        }
        else if (obj instanceof Comment) {
            add(index, (Comment) obj);
        }
        else if (obj instanceof ProcessingInstruction) {
            add(index, (ProcessingInstruction) obj);
        }
        else if (obj instanceof CDATA) {
            add(index, (CDATA) obj);
        }
        else if (obj instanceof EntityRef) {
            add(index, (EntityRef) obj);
        }
        else {
            if (obj == null) {
                throw new IllegalAddException("Cannot add null object");
            }
            else {
                throw new IllegalAddException("Class " +
                             obj.getClass().getName() +
                             " is of unrecognized type and cannot be 
added");
            }
        }
    }

Now that CDATA is a subclass of Text, the CDATA block is unreachable. We 
should either move it before the Text block or delete it completely. I 
think we're OK by removing it completely. The same issue occurs in the 
removeParent() method. This should not break anybody's code.

Whiile we're at it, it probably wouldn't hurt to grep on "instanceof 
CDATA" to try and pick up other files that might have this problem.

-- 
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+ 
|           The XML Bible, 2nd Edition (IDG Books, 2001)             |
|             http://www.cafeconleche.org/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:   http://www.cafeaulait.org/     | 
|  Read Cafe con Leche for XML News:  http://www.cafeconleche.org/   |
+----------------------------------+---------------------------------+





More information about the jdom-interest mailing list