You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Peter Seiderer <Pe...@ciselant.de> on 2002/03/07 14:35:25 UTC
java.lang.NullPointerException with DOMTransformer
Hello,
since Cocoon-2.0.1 I get a java.lang.NullPointerException when I trie to
use a DOMTransformer, see the attached soucce code for a DummyDOMTransformer:
--- begin file: de/ciselant/cocoon/transformation/DummyDOMTransformer ---
package de.ciselant.cocoon.transformation;
import org.apache.cocoon.transformation.AbstractDOMTransformer;
import org.w3c.dom.Document;
public class DummyDOMTransformer extends AbstractDOMTransformer {
public Document transform(Document doc) {
return doc;
}
}
--- end ---
Build into the sitemap.xmap via:
...
<map:transformer name="dummyDom" src="de.ciselant.cocoon.transformation.DummyDOMTransformer"/>
...
...
<map:match pattern="test.xml">
<map:generate src="test_file.xml"/>
<map:transform type="dummyDom" />
<map:serialize/>
</map:match>
...
And attach via jdb to the tomcat:
jdb -attach localhost:8000
Initializing jdb...
>
VM Started: No frames on the current call stack
main[1] cont
> catch java.lang.NullPointerException
Set exception catch java.lang.NullPointerException
>
Exception occurred: java.lang.NullPointerException (to be caught at: org.apache.xerces.framework.XMLParser.parse(), line=1109, bci=46) thread="Thread-11", org.apache.cocoon.xml.dom.DOMBuilder.getDocument(), line=123, bci=7
Thread-11[1] where
[1] org.apache.cocoon.xml.dom.DOMBuilder.getDocument (DOMBuilder.java:123)
[2] org.apache.cocoon.xml.dom.DOMBuilder.notifyListener (DOMBuilder.java:148)
[3] org.apache.cocoon.xml.dom.DOMBuilder.endDocument (DOMBuilder.java:140)
[4] org.apache.cocoon.components.sax.XMLTeePipe.endDocument (XMLTeePipe.java:59)
[5] org.apache.xerces.parsers.SAXParser.endDocument (SAXParser.java:1230)
[6] org.apache.xerces.validators.common.XMLValidator.callEndDocument (XMLValidator.java:1146)
[7] org.apache.xerces.framework.XMLDocumentScanner$EndOfInputDispatcher.dispatch (XMLDocumentScanner.java:1499)
[8] org.apache.xerces.framework.XMLDocumentScanner.parseSome (XMLDocumentScanner.java:381)
[9] org.apache.xerces.framework.XMLParser.parse (XMLParser.java:1098)
[10] org.apache.cocoon.components.parser.JaxpParser.parse (JaxpParser.java:182)
[11] org.apache.cocoon.components.source.URLSource.toSAX (URLSource.java:331)
[12] org.apache.cocoon.generation.FileGenerator.generate (FileGenerator.java:109)
[13] org.apache.cocoon.components.pipeline.CachingEventPipeline.process (CachingEventPipeline.java:209)
[14] org.apache.cocoon.components.pipeline.CachingStreamPipeline.process (CachingStreamPipeline.java:355)
[15] org.apache.cocoon.www.tandem.sitemap_xmap.matchN10146 (sitemap_xmap.java:1377)
[16] org.apache.cocoon.www.tandem.sitemap_xmap.process (sitemap_xmap.java:620)
[17] org.apache.cocoon.www.tandem.sitemap_xmap.process (sitemap_xmap.java:520)
[18] org.apache.cocoon.sitemap.Handler.process (Handler.java:180)
[19] org.apache.cocoon.sitemap.Manager.invoke (Manager.java:127)
[20] org.apache.cocoon.www.sitemap_xmap.matchN101CE (sitemap_xmap.java:1585)
[21] org.apache.cocoon.www.sitemap_xmap.process (sitemap_xmap.java:1320)
[22] org.apache.cocoon.www.sitemap_xmap.process (sitemap_xmap.java:1235)
[23] org.apache.cocoon.sitemap.Handler.process (Handler.java:180)
[24] org.apache.cocoon.sitemap.Manager.invoke (Manager.java:127)
[25] org.apache.cocoon.sitemap.SitemapManager.process (SitemapManager.java:144)
[26] org.apache.cocoon.Cocoon.process (Cocoon.java:582)
[27] org.apache.cocoon.servlet.CocoonServlet.service (CocoonServlet.java:795)
[28] javax.servlet.http.HttpServlet.service (HttpServlet.java:853)
[29] org.apache.tomcat.core.ServletWrapper.doService (ServletWrapper.java:405)
[30] org.apache.tomcat.core.Handler.service (Handler.java:287)
[31] org.apache.tomcat.core.ServletWrapper.service (ServletWrapper.java:372)
[32] org.apache.tomcat.core.ContextManager.internalService (ContextManager.java:806)
[33] org.apache.tomcat.core.ContextManager.service (ContextManager.java:752)
[34] org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection (Ajp12ConnectionHandler.java:166)
[35] org.apache.tomcat.service.TcpWorkerThread.runIt (PoolTcpEndpoint.java:416)
[36] org.apache.tomcat.util.ThreadPool$ControlRunnable.run (ThreadPool.java:501)
[37] java.lang.Thread.run (Thread.java:484)
Thread-11[1]
The default constructor from DOMBuilder is called, so this.restult.getNode()
returns null, so the line 123 produces the NullPointerException:
public Document getDocument() {
line 123: if (this.result.getNode().getNodeType() == Node.DOCUMENT_NODE) {
return ( (Document)this.result.getNode() );
} else {
return ( this.result.getNode().getOwnerDocument() );
}
}
Does anybody know some help?
Peter
--
------------------------------------------------------------------------
Peter Seiderer E-Mail: Peter.Seiderer@ciselant.de
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org
Re: java.lang.NullPointerException with DOMTransformer
Posted by Peter Seiderer <Pe...@ciselant.de>.
Hello,
thank you for the patch, now it works partly, the first access to
a URL (eg. http://localhost/test.xml) where the DummyDOMTransfomer is
in the pipline succeeds, but a next access on the same URL with
different submit paramters (eg. http://localhost/test.xml?bla=blub)
failes with java.lang.NullPointerException ......
Peter
Trace from error log follows:
java.lang.NullPointerException
at org.apache.cocoon.xml.dom.DOMBuilder.getDocument(DOMBuilder.java:123)
at org.apache.cocoon.xml.dom.DOMBuilder.notifyListener(DOMBuilder.java:148)
at org.apache.cocoon.xml.dom.DOMBuilder.endDocument(DOMBuilder.java:140)
at org.apache.cocoon.transformation.AbstractDOMTransformer.endDocument(AbstractDOMTransformer.java:203)
at org.apache.cocoon.components.sax.XMLByteStreamInterpreter.parse(XMLByteStreamInterpreter.java:69)
at org.apache.cocoon.components.sax.XMLByteStreamInterpreter.deserialize(XMLByteStreamInterpreter.java:59)
at org.apache.cocoon.components.pipeline.CachingEventPipeline.process(CachingEventPipeline.java:177)
at org.apache.cocoon.components.pipeline.CachingStreamPipeline.process(C
achingStreamPipeline.java:355)
at org.apache.cocoon.www.tandem.sitemap_xmap.matchN10146(sitemap_xmap.java:1377)
at org.apache.cocoon.www.tandem.sitemap_xmap.process(sitemap_xmap.java:620)
at org.apache.cocoon.www.tandem.sitemap_xmap.process(sitemap_xmap.java:520)
at org.apache.cocoon.sitemap.Handler.process(Handler.java:180)
at org.apache.cocoon.sitemap.Manager.invoke(Manager.java:127)
at org.apache.cocoon.www.sitemap_xmap.matchN101CE(sitemap_xmap.java:1585)
at org.apache.cocoon.www.sitemap_xmap.process(sitemap_xmap.java:1320)
....
On Thu, Mar 07, 2002 at 10:47:47AM -0500, Vadim Gritsenko wrote:
> This is a known issue and I have patch sitting on my disk. It is not
> 100% tested yet and might have some errors, thus not commited to CVS.
> I'm attaching patched file so you can try it.
>
> Vadim
>
--
------------------------------------------------------------------------
Peter Seiderer E-Mail: Peter.Seiderer@ciselant.de
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org
RE: java.lang.NullPointerException with DOMTransformer
Posted by Vadim Gritsenko <va...@verizon.net>.
Thanks, it's in CVS.
Vadim
> From: Peter Seiderer [mailto:Peter.Seiderer@ciselant.de]
>
> Hello Vadim,
> sorry but you new patch gives although a NullPointerException, I even
> added
> this.setContentHandler(this.handler);
> this.setLexicalHandler(this.handler);
> to the recycle because both handler are set to null in
> DOMBuilder-->AbstractXMLPipe-->AbstractXMLProducer.recycle(), but
> this leads to some error reporting about only one root element for
document
> allowed.
>
> So my suggested patch (suboptimal but working)
> - without attribute this.hadler
> - with attribute this.paretnNode
> looks like the following:
>
> ---
work/cocoon-2.0.1/src/java/org/apache/cocoon/xml/dom/DOMBuilder.java_ori
g
> Fri Mar 8 17:51:11 2002
> +++
work/cocoon-2.0.1/src/java/org/apache/cocoon/xml/dom/DOMBuilder.java
> Fri Mar 8 19:53:47 2002
> @@ -35,6 +35,9 @@
> /** The result */
> protected DOMResult result;
>
> + /** The parentNode */
> + protected Node parentNode;
> +
> /**
> * Construct a new instance of this TreeGenerator.
> */
> @@ -83,6 +86,7 @@
> TransformerHandler handler =
factory.newTransformerHandler();
> this.setContentHandler(handler);
> this.setLexicalHandler(handler);
> + this.parentNode = parentNode;
> if (parentNode != null) {
> this.result = new DOMResult( parentNode );
> } else {
> @@ -109,7 +113,21 @@
> */
> public void recycle() {
> super.recycle();
> - this.result = null;
> + try {
> + TransformerHandler handler =
factory.newTransformerHandler();
> + this.setContentHandler(handler);
> + this.setLexicalHandler(handler);
> + if (this.parentNode != null) {
> + this.result = new DOMResult(this.parentNode);
> + } else {
> + this.result = new DOMResult();
> + }
> + handler.setResult(this.result);
> +
> + } catch (javax.xml.transform.TransformerException local) {
> + throw new RuntimeException("Fatal-Error: Unable to get
> transformer handler");
> + }
> +
> }
>
> /**
>
> Peter
>
>
> On Thu, Mar 07, 2002 at 05:50:52PM -0500, Vadim Gritsenko wrote:
> > I do not like re-creating transformer every time; it's quite
expensive
> > operation (IIRC). It should be enough just provide new result object
> > instance.
> >
> > Could you try attached version?
> >
> > Thanks,
> > Vadim
>
>
> --
>
------------------------------------------------------------------------
> Peter Seiderer E-Mail: Peter.Seiderer@ciselant.de
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org
Re: java.lang.NullPointerException with DOMTransformer
Posted by Peter Seiderer <Pe...@ciselant.de>.
Hello Vadim,
sorry but you new patch gives although a NullPointerException, I even
added
this.setContentHandler(this.handler);
this.setLexicalHandler(this.handler);
to the recycle because both handler are set to null in
DOMBuilder-->AbstractXMLPipe-->AbstractXMLProducer.recycle(), but
this leads to some error reporting about only one root element for document
allowed.
So my suggested patch (suboptimal but working)
- without attribute this.hadler
- with attribute this.paretnNode
looks like the following:
--- work/cocoon-2.0.1/src/java/org/apache/cocoon/xml/dom/DOMBuilder.java_orig Fri Mar 8 17:51:11 2002
+++ work/cocoon-2.0.1/src/java/org/apache/cocoon/xml/dom/DOMBuilder.java Fri Mar 8 19:53:47 2002
@@ -35,6 +35,9 @@
/** The result */
protected DOMResult result;
+ /** The parentNode */
+ protected Node parentNode;
+
/**
* Construct a new instance of this TreeGenerator.
*/
@@ -83,6 +86,7 @@
TransformerHandler handler = factory.newTransformerHandler();
this.setContentHandler(handler);
this.setLexicalHandler(handler);
+ this.parentNode = parentNode;
if (parentNode != null) {
this.result = new DOMResult( parentNode );
} else {
@@ -109,7 +113,21 @@
*/
public void recycle() {
super.recycle();
- this.result = null;
+ try {
+ TransformerHandler handler = factory.newTransformerHandler();
+ this.setContentHandler(handler);
+ this.setLexicalHandler(handler);
+ if (this.parentNode != null) {
+ this.result = new DOMResult(this.parentNode);
+ } else {
+ this.result = new DOMResult();
+ }
+ handler.setResult(this.result);
+
+ } catch (javax.xml.transform.TransformerException local) {
+ throw new RuntimeException("Fatal-Error: Unable to get transformer handler");
+ }
+
}
/**
Peter
On Thu, Mar 07, 2002 at 05:50:52PM -0500, Vadim Gritsenko wrote:
> I do not like re-creating transformer every time; it's quite expensive
> operation (IIRC). It should be enough just provide new result object
> instance.
>
> Could you try attached version?
>
> Thanks,
> Vadim
--
------------------------------------------------------------------------
Peter Seiderer E-Mail: Peter.Seiderer@ciselant.de
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org
Re: java.lang.NullPointerException with DOMTransformer
Posted by Peter Seiderer <Pe...@ciselant.de>.
Hello,
the following patch is a solution for the second NullPointerException (but
I am not sure if it is the best/right solution):
diff -u cocoon-2.0.1/src/java/org/apache/cocoon/xml/dom/DOMBuilder.java_orig cocoon-2.0.1/src/java/org/apache/cocoon/xml/dom/DOMBuilder.java
--- cocoon-2.0.1/src/java/org/apache/cocoon/xml/dom/DOMBuilder.java_orig Thu Mar 7 18:18:04 2002
+++ cocoon-2.0.1/src/java/org/apache/cocoon/xml/dom/DOMBuilder.java Thu Mar 7 18:26:47 2002
@@ -35,6 +35,9 @@
/** The result */
protected DOMResult result;
+ /** The TransformerHandler */
+ protected TransformerHandler handler;
+
/**
* Construct a new instance of this TreeGenerator.
*/
@@ -81,7 +84,7 @@
System.err.println("DOMBuilder( Listener listener, Node parentNode )");
this.listener = listener;
try {
- TransformerHandler handler = factory.newTransformerHandler();
+ handler = factory.newTransformerHandler();
this.setContentHandler(handler);
this.setLexicalHandler(handler);
if (parentNode != null) {
@@ -113,7 +116,15 @@
*/
public void recycle() {
super.recycle();
- this.result = null;
+ try {
+ this.handler = factory.newTransformerHandler();
+ this.setContentHandler(handler);
+ this.setLexicalHandler(handler);
+ this.result = new DOMResult();
+ handler.setResult(this.result);
+ } catch (javax.xml.transform.TransformerException local) {
+ throw new RuntimeException("Fatal-Error: Unable to get transformer handler");
+ }
}
/**
--
------------------------------------------------------------------------
Peter Seiderer E-Mail: Peter.Seiderer@ciselant.de
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org
RE: java.lang.NullPointerException with DOMTransformer
Posted by Vadim Gritsenko <va...@verizon.net>.
This is a known issue and I have patch sitting on my disk. It is not
100% tested yet and might have some errors, thus not commited to CVS.
I'm attaching patched file so you can try it.
Vadim
> From: Peter Seiderer [mailto:Peter.Seiderer@ciselant.de]
>
> Hello,
> since Cocoon-2.0.1 I get a java.lang.NullPointerException when I trie
to
> use a DOMTransformer, see the attached soucce code for a
DummyDOMTransformer:
>
> --- begin file: de/ciselant/cocoon/transformation/DummyDOMTransformer
---
>
> package de.ciselant.cocoon.transformation;
>
> import org.apache.cocoon.transformation.AbstractDOMTransformer;
> import org.w3c.dom.Document;
>
> public class DummyDOMTransformer extends AbstractDOMTransformer {
> public Document transform(Document doc) {
> return doc;
> }
> }
>
> --- end ---
>
> Build into the sitemap.xmap via:
> ...
> <map:transformer name="dummyDom"
> src="de.ciselant.cocoon.transformation.DummyDOMTransformer"/>
> ...
> ...
> <map:match pattern="test.xml">
> <map:generate src="test_file.xml"/>
> <map:transform type="dummyDom" />
> <map:serialize/>
> </map:match>
> ...
>
>
> And attach via jdb to the tomcat:
> jdb -attach localhost:8000
> Initializing jdb...
> >
> VM Started: No frames on the current call stack
>
> main[1] cont
> > catch java.lang.NullPointerException
> Set exception catch java.lang.NullPointerException
> >
> Exception occurred: java.lang.NullPointerException (to be caught at:
> org.apache.xerces.framework.XMLParser.parse(), line=1109, bci=46)
> thread="Thread-11",
org.apache.cocoon.xml.dom.DOMBuilder.getDocument(),
> line=123, bci=7
>
> Thread-11[1] where
> [1] org.apache.cocoon.xml.dom.DOMBuilder.getDocument
(DOMBuilder.java:123)
> [2] org.apache.cocoon.xml.dom.DOMBuilder.notifyListener
> (DOMBuilder.java:148)
> [3] org.apache.cocoon.xml.dom.DOMBuilder.endDocument
(DOMBuilder.java:140)
> [4] org.apache.cocoon.components.sax.XMLTeePipe.endDocument
> (XMLTeePipe.java:59)
> [5] org.apache.xerces.parsers.SAXParser.endDocument
(SAXParser.java:1230)
> [6] org.apache.xerces.validators.common.XMLValidator.callEndDocument
> (XMLValidator.java:1146)
> [7]
>
org.apache.xerces.framework.XMLDocumentScanner$EndOfInputDispatcher.disp
atch
> (XMLDocumentScanner.java:1499)
> [8] org.apache.xerces.framework.XMLDocumentScanner.parseSome
> (XMLDocumentScanner.java:381)
> [9] org.apache.xerces.framework.XMLParser.parse
(XMLParser.java:1098)
> [10] org.apache.cocoon.components.parser.JaxpParser.parse
> (JaxpParser.java:182)
> [11] org.apache.cocoon.components.source.URLSource.toSAX
> (URLSource.java:331)
> [12] org.apache.cocoon.generation.FileGenerator.generate
> (FileGenerator.java:109)
> [13]
org.apache.cocoon.components.pipeline.CachingEventPipeline.process
> (CachingEventPipeline.java:209)
> [14]
org.apache.cocoon.components.pipeline.CachingStreamPipeline.process
> (CachingStreamPipeline.java:355)
> [15] org.apache.cocoon.www.tandem.sitemap_xmap.matchN10146
> (sitemap_xmap.java:1377)
> [16] org.apache.cocoon.www.tandem.sitemap_xmap.process
> (sitemap_xmap.java:620)
> [17] org.apache.cocoon.www.tandem.sitemap_xmap.process
> (sitemap_xmap.java:520)
> [18] org.apache.cocoon.sitemap.Handler.process (Handler.java:180)
> [19] org.apache.cocoon.sitemap.Manager.invoke (Manager.java:127)
> [20] org.apache.cocoon.www.sitemap_xmap.matchN101CE
(sitemap_xmap.java:1585)
> [21] org.apache.cocoon.www.sitemap_xmap.process
(sitemap_xmap.java:1320)
> [22] org.apache.cocoon.www.sitemap_xmap.process
(sitemap_xmap.java:1235)
> [23] org.apache.cocoon.sitemap.Handler.process (Handler.java:180)
> [24] org.apache.cocoon.sitemap.Manager.invoke (Manager.java:127)
> [25] org.apache.cocoon.sitemap.SitemapManager.process
> (SitemapManager.java:144)
> [26] org.apache.cocoon.Cocoon.process (Cocoon.java:582)
> [27] org.apache.cocoon.servlet.CocoonServlet.service
> (CocoonServlet.java:795)
> [28] javax.servlet.http.HttpServlet.service (HttpServlet.java:853)
> [29] org.apache.tomcat.core.ServletWrapper.doService
> (ServletWrapper.java:405)
> [30] org.apache.tomcat.core.Handler.service (Handler.java:287)
> [31] org.apache.tomcat.core.ServletWrapper.service
(ServletWrapper.java:372)
> [32] org.apache.tomcat.core.ContextManager.internalService
> (ContextManager.java:806)
> [33] org.apache.tomcat.core.ContextManager.service
(ContextManager.java:752)
> [34]
>
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnec
tion
> (Ajp12ConnectionHandler.java:166)
> [35] org.apache.tomcat.service.TcpWorkerThread.runIt
> (PoolTcpEndpoint.java:416)
> [36] org.apache.tomcat.util.ThreadPool$ControlRunnable.run
> (ThreadPool.java:501)
> [37] java.lang.Thread.run (Thread.java:484)
> Thread-11[1]
>
>
> The default constructor from DOMBuilder is called, so
this.restult.getNode()
> returns null, so the line 123 produces the NullPointerException:
>
> public Document getDocument() {
> line 123: if (this.result.getNode().getNodeType() ==
Node.DOCUMENT_NODE) {
> return ( (Document)this.result.getNode() );
> } else {
> return ( this.result.getNode().getOwnerDocument() );
> }
> }
>
> Does anybody know some help?
>
> Peter
>
> --
>
------------------------------------------------------------------------
> Peter Seiderer E-Mail: Peter.Seiderer@ciselant.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org