Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-890

[PATCH] NullPointerException calling cloneNode for SVG 1.2 documents

    XMLWordPrintableJSON

Details

    Description

      If you call the Node#cloneNode(boolean) method to perform a deep clone of an element in an SVG 1.2 document, and that element has got a child element in a custom namespace, a NullPointerException is thrown:

      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)

      In SVG 1.1 documents, this does not happen.

      The problem is that the cloning behaviour of BindableElement is implemented incorrectly. The newNode() method calls the wrong constructor, so that some super constructor executes code relying on the owner document of the node aready being set.

      Attached is a patch for this bug. The cloning behaviour is now implemented just as the one of GenericElementNS, the class used for custom namespace elements in SVG 1.1. This means that in the newNode() method, we just call the parameterless constructor. To ensure that the fields of BindableElement are set, I added implementations for the copyInto, deepCopyInto, export, and deepExport methods.

      Attachments

        1. clonenode.patch
          2 kB
          Daniel Westheide
        2. Batik-Bug46791-TestCase.svg
          0.4 kB
          Helder Magalhães
        3. Batik-Bug46791-TestCaseComparison.svg
          0.4 kB
          Helder Magalhães
        4. bug46791.patch
          2 kB
          Daniel Westheide

        Issue Links

          Activity

            People

              batik-dev@xmlgraphics.apache.org Batik Developer's Mailing list
              daniel.westheide@gmx.de Daniel Westheide
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: