[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Null values in text nodes



The program:
------------

import org.w3c.dom.*;
import org.ozoneDB.xml.dom.*;

public class MonsterDOMTest
{
    public static void main(String[] args)
    {
	DocumentImpl doc = new DocumentImpl();
	Text filledText = new TextImpl();
	((TextImpl)filledText).init(doc, "testdata");
	System.out.println(filledText.toString());
	Text emptyText = new TextImpl();
	((TextImpl)emptyText).init(doc, null);
	System.out.println(emptyText.toString()); // line 14
    }
}

The error message:
------------------

Text node: [testdata]
Exception in thread "main" java.lang.NullPointerException: 
        at org.ozoneDB.xml.dom.TextImpl.toString(TextImpl.java:98)
        at MonsterDOMTest.main(MonsterDOMTest.java:14)

The problem is that the value of a TextNode may be set to null without
problems,
but this is forbidden by the DOM specification.
Other parts of the class rely on a non-null value.

Solution:
---------

In all init() methods of Nodes that may have values, it has to
be checked that a value null is stored not as null, but as "".

Michael Keuchen