You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Daniel Westheide <d....@iplabs.de> on 2009/02/18 16:00:30 UTC

NPE calling cloneNode for SVG 1.2 documents

Hi,

I stumbled upon a problem concerning deep cloning of nodes in SVG 1.2  
documents. I have got an SVG 1.2 document with a metadata element that  
has got a child element in a custom namespace. Now, if I try to get a  
deep clone of any direct or indirect parent of that custom element by  
calling the node.clone(true), I get a NullPointerException, because  
the owner document of the cloned custom element is not set.

My SVG document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<svg externalResourcesRequired="true" height="300mm"
   preserveAspectRatio="none" version="1.2" viewBox="0 0 300 300"
   width="300mm" xmlns="http://www.w3.org/2000/svg"
   xmlns:cns="http://my/custom/namespace" xmlns:xlink="http://www.w3.org/1999/xlink 
">
     <g>
       <metadata>
         <cns:mymetadata attr1="value" attr2="value" />
       </metadata>
       <g transform="translate(24.745000000000005 18.049999999999997)  
rotate(0)">
         <rect width="100" height="50" fill="red" />
       </g>
     </g>
</svg>


The stacktrace I get is the following:

Exception in thread "main" java.lang.NullPointerException
	at  
org 
.apache 
.batik.dom.svg.SVGOMElement.createLiveAnimatedString(SVGOMElement.java: 
390)
	at  
org 
.apache 
.batik 
.dom 
.svg 
.SVGStylableElement.initializeLiveAttributes(SVGStylableElement.java: 
118)
	at  
org 
.apache 
.batik.dom.svg.SVGStylableElement.<init>(SVGStylableElement.java:103)
	at  
org 
.apache 
.batik.dom.svg.SVGGraphicsElement.<init>(SVGGraphicsElement.java:96)
	at  
org.apache.batik.dom.svg12.BindableElement.<init>(BindableElement.java: 
68)
	at  
org 
.apache.batik.dom.svg12.BindableElement.newNode(BindableElement.java:99)
	at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:309)
	at  
org 
.apache 
.batik.dom.AbstractParentNode.deepCopyInto(AbstractParentNode.java:377)
	at  
org.apache.batik.dom.AbstractElement.deepCopyInto(AbstractElement.java: 
563)
	at  
org.apache.batik.dom.svg.SVGOMElement.deepCopyInto(SVGOMElement.java: 
891)
	at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:309)
	at  
org 
.apache 
.batik.dom.AbstractParentNode.deepCopyInto(AbstractParentNode.java:377)
	at  
org.apache.batik.dom.AbstractElement.deepCopyInto(AbstractElement.java: 
563)
	at  
org.apache.batik.dom.svg.SVGOMElement.deepCopyInto(SVGOMElement.java: 
891)
	at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:309)
	at  
org 
.apache 
.batik.dom.AbstractParentNode.deepCopyInto(AbstractParentNode.java:377)
	at  
org.apache.batik.dom.AbstractElement.deepCopyInto(AbstractElement.java: 
563)
	at  
org.apache.batik.dom.svg.SVGOMElement.deepCopyInto(SVGOMElement.java: 
891)
	at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:309)
	at CloneNodeTest.main(CloneNodeTest.java:25)


When change the version of the SVG document to 1.1, everything works  
fine.

I already did some debugging, and apparently, the custom  
cns:mymetadata element from my example SVG document is being  
represented by a BindableElement if the SVG12DOMImplementation is  
used, whereas it is a GenericElementNS for SVG 1.1. I don't know if  
this by itself is already the problem that causes the NPE. But at  
least I find it somewhat strange that a custom element that is a child  
of an SVG metadata element and will thus never ever be rendered, is  
represented by a subclass of SVGGraphicsElement.

I managed to get rid of this problem by patching Batik so that the  
SVG12DOMImplementation always returns a GenericElementNS instead of a  
BindableElement. But I suppose that this is not really an acceptable  
solution to the problem because custom elements that are not children  
of a metadata element and are thus supposed to be rendered will not  
work any more.

Any help with this problem is much appreciated.

Thanks in advance,

Daniel



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


Re: NPE calling cloneNode for SVG 1.2 documents

Posted by Daniel Westheide <d....@iplabs.de>.
Am 25.02.2009 um 13:00 schrieb Helder Magalhães:
>
> By your message (I haven't tried to reproduce) I'd say that the patch
> should be in the direction of making "BindableElement" return an owner
> element (probably imitating the behavior of "GenericElementNS"). If
> you are able to create a patch, please consider contributing it. ;-)

Hey Helder,

thanks for your reply. I will take a closer look at this again and try  
to find the place where copying of the owner document is omitted. And  
of course, if I can create a patch, I will contribute it to the Batik  
project. :)

Best regards,

Daniel


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


Re: NPE calling cloneNode for SVG 1.2 documents

Posted by Daniel Westheide <d....@iplabs.de>.
Hi Helder,

> As none of the Batik committers [1] has replied in a few days, I can
> imagine there's currently lack of time to deal with it, at least
> within the mailing list -- it might end up getting lost. With that in
> mind, I'd recommend creating a new bug report and attaching the patch
> there. I'd also suggest leaving a link to this thread [2] in the bug
> report and pasting a link to the bug on this thread also, so that
> someone which stumbles in one of them can easily jump to the other,
> use this thread for discussion, bug's history and background, etc. ;-)

Thanks for your reply. The bug report and my patch can be found at

https://issues.apache.org/bugzilla/show_bug.cgi?id=46791

Best regards,

Daniel


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


Re: NPE calling cloneNode for SVG 1.2 documents

Posted by Helder Magalhães <he...@gmail.com>.
Hi Daniel,


> I created a patch for this bug. The problem was that the newNode() method
> was using the wrong constructor, so that some super constructor executed
> code relying on the owner document aready being set. With my patch, the
> cloning behaviour of BindableElement is like that of GenericElementNS.
> I would like to contribute my patch to the Batik project.

It's great that you choose to contribute to Batik. :-)


> Should I post it here, to the developer's mailing list,
> or rather create a bug report on Bugzilla and attach it there?

As none of the Batik committers [1] has replied in a few days, I can
imagine there's currently lack of time to deal with it, at least
within the mailing list -- it might end up getting lost. With that in
mind, I'd recommend creating a new bug report and attaching the patch
there. I'd also suggest leaving a link to this thread [2] in the bug
report and pasting a link to the bug on this thread also, so that
someone which stumbles in one of them can easily jump to the other,
use this thread for discussion, bug's history and background, etc. ;-)


> Thanks and best regards,

Best regards,
 Helder Magalhães


[1] http://xmlgraphics.apache.org/batik/contributors.html#committers
[2] http://www.nabble.com/NPE-calling-cloneNode-for-SVG-1.2-documents-td22080561.html

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


Re: NPE calling cloneNode for SVG 1.2 documents

Posted by Daniel Westheide <d....@iplabs.de>.
Hi,

> element (probably imitating the behavior of "GenericElementNS"). If
> you are able to create a patch, please consider contributing it. ;-)

I created a patch for this bug. The problem was that the newNode()  
method was using the wrong constructor, so that some super constructor  
executed code relying on the owner document aready being set. With my  
patch, the cloning behaviour of BindableElement is like that of  
GenericElementNS.

I would like to contribute my patch to the Batik project. Should I  
post it here, to the developer's mailing list, or rather create a bug  
report on Bugzilla and attach it there?

Thanks and best regards,

Daniel

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


Re: NPE calling cloneNode for SVG 1.2 documents

Posted by Helder Magalhães <he...@gmail.com>.
> I get a NullPointerException, because the owner document
> of the cloned custom element is not set.
[...]
> I managed to get rid of this problem by patching Batik so that the
> SVG12DOMImplementation always returns a GenericElementNS instead of a
> BindableElement. But I suppose that this is not really an acceptable
> solution to the problem because custom elements that are not children of a
> metadata element and are thus supposed to be rendered will not work any
> more.

By your message (I haven't tried to reproduce) I'd say that the patch
should be in the direction of making "BindableElement" return an owner
element (probably imitating the behavior of "GenericElementNS"). If
you are able to create a patch, please consider contributing it. ;-)

Regards,
 Helder

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