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

Re: Null values in text nodes



On Wed, 22 Nov 2000, Michael Keuchen wrote:
> 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 "".

This just hides an error of the programmer (more exactly: the entity that
created the wrong init() method call) If this is true, then I don't like this
solution. To me throwing an exception seems to be a better solution.


Falko
-- 
______________________________________________________________________
Falko Braeutigam                              mailto:falko@smb-tec.com
SMB GmbH                                        http://www.smb-tec.com