Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1180

Document root changes indirectly during DeferredDocumentImpl children modification

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.8.0
    • 2.8.1
    • DOM (Level 3 Core)
    • None
    • java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

    Description

      In the example below last line causes org.w3c.dom.DOMException because document root is already defined.

      import java.io.ByteArrayInputStream;
      import java.io.InputStream;

      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;

      import org.w3c.dom.Document;
      import org.w3c.dom.Element;

      public class SetRootTest {
      public static void main(String[] args) throws Exception

      { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputStream inputStream = new ByteArrayInputStream("<root><a><b/></a></root>".getBytes()); Document document = builder.parse(inputStream); Element root = document.getDocumentElement(); Element a = (Element) root.getChildNodes().item(0); document.removeChild(root); System.out.println(document.getDocumentElement()); a.getFirstChild(); System.out.println(document.getDocumentElement()); document.appendChild(root);//exception here }

      }

      The program output:
      null
      [b: null]
      Exception in thread "main" org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
      at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:419)
      at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:275)
      at SetRootTest.main(SetRootTest.java:27)

      Attachments

        Activity

          People

            mrglavas@ca.ibm.com Michael Glavassevich
            ysemikhatsky Yury Semikhatsky
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: