You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Michael Wirz <mi...@abs.de> on 2005/11/22 16:47:01 UTC

Error in org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer or xerces DocumentImpl

Hello Coocon User Mailing List,

During cocoon app development the following error arose using DOM-Documents
and the SAX-Streaming of cocoon. Since I am not sure if its a bug in cocoons
DOM->SAX Streamer or the Document Implementation of xerces I'd like to show
it to you first. Maybe you can help deciding if it is to be forwarded to
cocoon-dev
or another place.

I built a DOM - Tree using the xerces DocumentImpl Documt-Class.
I then added a root Node with a Text Element, initialized (erratically)
with null.
see below:

Document doc = new DocumentImpl();
Element e = doc.createelement("rootNode");
doc.appendChild(e);
e.appendChild(doc.createTextNode(null));

This has been a valid DOM-Document and could be serialized using the
org.apache.xml.serialize.XMLSerializer and written to a file successfully.

When using this DOM-Tree in an <xsp:expr> in cocoon a NullPointerException
occurred:

Original Exception: java.lang.NullPointerException
	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.dispatchChars(DOMStreamer.java:264)
	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.startNode(DOMStreamer.java:471)
	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.stream(DOMStreamer.java:229)
	at org.apache.cocoon.xml.dom.DOMStreamer.stream(DOMStreamer.java:150)
	at org.apache.cocoon.components.language.markup.xsp.XSPObjectHelper.xspExpr(XSPObjectHelper.java:309)
	at ... the xsp-compiled java src ...

I took a look at
*org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer.
dispatchChars looks like this:

        private final void dispatchChars(Node node) throws SAXException {
            String data = ((Text) node).getData();
            contentHandler.characters(data.toCharArray(), 0, data.length());
        }

If getData() yields null, subsequent calls will fail; resulting in my
NullPointerException.

I fixed my DOM-Tree making things work.
Do we have to fix it in
**org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer?
Or is the DOM invalid according to the DOM Spec, in other words: is a
null-Data-Element allowed in a TextNode?

Thanks a lot for your attention and hints on that topic,
from near Munich, Germany,
Michael Wirz
**
*

-- 
abs IT Service GmbH
abs gruppe
Michael Wirz
Entwicklung

Landsberger Straße 57
82266 Stegen am Ammersee
Telefon: +49 (0)8143 999 43
Telefax: +49 (0)8143 999 49

Michael.Wirz@abs.de
www.eFonds24.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Error in org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer or xerces DocumentImpl

Posted by Joerg Heinicke <jo...@gmx.de>.
On 25.11.2005 12:11, Michael Wirz wrote:

> I didnt find an answer as well: the data can be of zero length it is
> stated there but the technically possible null value is not mentioned.
> I could not find any place stating that null is not allowed except
> elsewhere mentioned...

Why not just add the null check? If it is not stated anywhere that the 
data must not be null, we should assume it can be and check for it - 
defensive programming. Even if null would not be allowed, it would be 
better to check for null and throw an appropriate exception.

Jörg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Error in org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer or xerces DocumentImpl

Posted by Michael Wirz <mi...@abs.de>.
>On Tue, 2005-11-22 at 16:47 +0100, Michael Wirz wrote:
>  
>
>>Hello Coocon User Mailing List,
>>
>>During cocoon app development the following error arose using DOM-Documents
>>and the SAX-Streaming of cocoon. Since I am not sure if its a bug in cocoons
>>DOM->SAX Streamer or the Document Implementation of xerces I'd like to show
>>it to you first. Maybe you can help deciding if it is to be forwarded to
>>cocoon-dev
>>or another place.
>>
>>I built a DOM - Tree using the xerces DocumentImpl Documt-Class.
>>I then added a root Node with a Text Element, initialized (erratically)
>>with null.
>>see below:
>>
>>Document doc = new DocumentImpl();
>>Element e = doc.createelement("rootNode");
>>doc.appendChild(e);
>>e.appendChild(doc.createTextNode(null));
>>
>>This has been a valid DOM-Document and could be serialized using the
>>org.apache.xml.serialize.XMLSerializer and written to a file successfully.
>>
>>When using this DOM-Tree in an <xsp:expr> in cocoon a NullPointerException
>>occurred:
>>
>>Original Exception: java.lang.NullPointerException
>>	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.dispatchChars(DOMStreamer.java:264)
>>	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.startNode(DOMStreamer.java:471)
>>	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.stream(DOMStreamer.java:229)
>>	at org.apache.cocoon.xml.dom.DOMStreamer.stream(DOMStreamer.java:150)
>>	at org.apache.cocoon.components.language.markup.xsp.XSPObjectHelper.xspExpr(XSPObjectHelper.java:309)
>>	at ... the xsp-compiled java src ...
>>
>>I took a look at
>>*org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer.
>>dispatchChars looks like this:
>>
>>        private final void dispatchChars(Node node) throws SAXException {
>>            String data = ((Text) node).getData();
>>            contentHandler.characters(data.toCharArray(), 0, data.length());
>>        }
>>
>>If getData() yields null, subsequent calls will fail; resulting in my
>>NullPointerException.
>>
>>I fixed my DOM-Tree making things work.
>>Do we have to fix it in
>>**org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer?
>>Or is the DOM invalid according to the DOM Spec, in other words: is a
>>null-Data-Element allowed in a TextNode?
>>    
>>
>
>You could look it up yourself too :-) I just had a quick look at the DOM
>spec, but for me it is unclear whether it is allowed to be null or not.
>It is not mentioned that it cannot be null, but it is neither mentioned
>that it can be null, while other methods that do allow null values for
>arguments do mention this.
>  
>
Thanks Bruno, for your answer.
You encouraged me to have a look into the spec and -- I did it ;-))
I havent been looking in this document but it is much more easy to read
than i excpected...
I didnt find an answer as well: the data can be of zero length it is
stated there
but the technically possible null value is not mentioned. I could not
find any
place stating that null is not allowed except elsewhere mentioned...

Do you know anyone who could answer this question?

Thank you,
Michael Wirz

-- 
abs IT Service GmbH
abs gruppe
Michael Wirz
Entwicklung

Landsberger Straße 57
82266 Stegen am Ammersee
Telefon: +49 (0)8143 999 43
Telefax: +49 (0)8143 999 49

Michael.Wirz@abs.de
www.eFonds24.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Error in org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer or xerces DocumentImpl

Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2005-11-22 at 16:47 +0100, Michael Wirz wrote:
> Hello Coocon User Mailing List,
> 
> During cocoon app development the following error arose using DOM-Documents
> and the SAX-Streaming of cocoon. Since I am not sure if its a bug in cocoons
> DOM->SAX Streamer or the Document Implementation of xerces I'd like to show
> it to you first. Maybe you can help deciding if it is to be forwarded to
> cocoon-dev
> or another place.
> 
> I built a DOM - Tree using the xerces DocumentImpl Documt-Class.
> I then added a root Node with a Text Element, initialized (erratically)
> with null.
> see below:
> 
> Document doc = new DocumentImpl();
> Element e = doc.createelement("rootNode");
> doc.appendChild(e);
> e.appendChild(doc.createTextNode(null));
> 
> This has been a valid DOM-Document and could be serialized using the
> org.apache.xml.serialize.XMLSerializer and written to a file successfully.
> 
> When using this DOM-Tree in an <xsp:expr> in cocoon a NullPointerException
> occurred:
> 
> Original Exception: java.lang.NullPointerException
> 	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.dispatchChars(DOMStreamer.java:264)
> 	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.startNode(DOMStreamer.java:471)
> 	at org.apache.cocoon.xml.dom.DOMStreamer$NamespaceNormalizingDOMStreamer.stream(DOMStreamer.java:229)
> 	at org.apache.cocoon.xml.dom.DOMStreamer.stream(DOMStreamer.java:150)
> 	at org.apache.cocoon.components.language.markup.xsp.XSPObjectHelper.xspExpr(XSPObjectHelper.java:309)
> 	at ... the xsp-compiled java src ...
> 
> I took a look at
> *org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer.
> dispatchChars looks like this:
> 
>         private final void dispatchChars(Node node) throws SAXException {
>             String data = ((Text) node).getData();
>             contentHandler.characters(data.toCharArray(), 0, data.length());
>         }
> 
> If getData() yields null, subsequent calls will fail; resulting in my
> NullPointerException.
> 
> I fixed my DOM-Tree making things work.
> Do we have to fix it in
> **org.apache.cocoon.xml.dom.DOMStreamer.NamespaceNormalizingDOMStreamer?
> Or is the DOM invalid according to the DOM Spec, in other words: is a
> null-Data-Element allowed in a TextNode?

You could look it up yourself too :-) I just had a quick look at the DOM
spec, but for me it is unclear whether it is allowed to be null or not.
It is not mentioned that it cannot be null, but it is neither mentioned
that it can be null, while other methods that do allow null values for
arguments do mention this.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org