You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Yury Semikhatsky (JIRA)" <xe...@xml.apache.org> on 2006/08/23 11:43:13 UTC

[jira] Created: (XERCESJ-1180) Document root changes indirectly during DeferredDocumentImpl children modification

Document root changes indirectly during DeferredDocumentImpl children modification
----------------------------------------------------------------------------------

                 Key: XERCESJ-1180
                 URL: http://issues.apache.org/jira/browse/XERCESJ-1180
             Project: Xerces2-J
          Issue Type: Bug
         Environment: 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)

            Reporter: Yury Semikhatsky


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)



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org


[jira] Updated: (XERCESJ-1180) Document root changes indirectly during DeferredDocumentImpl children modification

Posted by "Michael Glavassevich (JIRA)" <xe...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XERCESJ-1180?page=all ]

Michael Glavassevich updated XERCESJ-1180:
------------------------------------------

    Fix Version/s: 2.8.1

> Document root changes indirectly during DeferredDocumentImpl children modification
> ----------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1180
>                 URL: http://issues.apache.org/jira/browse/XERCESJ-1180
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: DOM (Level 3 Core)
>    Affects Versions: 2.8.0
>         Environment: 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)
>            Reporter: Yury Semikhatsky
>         Assigned To: Michael Glavassevich
>             Fix For: 2.8.1
>
>
> 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)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org


[jira] Updated: (XERCESJ-1180) Document root changes indirectly during DeferredDocumentImpl children modification

Posted by "Michael Glavassevich (JIRA)" <xe...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XERCESJ-1180?page=all ]

Michael Glavassevich updated XERCESJ-1180:
------------------------------------------

          Component/s: DOM (Level 3 Core)
    Affects Version/s: 2.8.0

> Document root changes indirectly during DeferredDocumentImpl children modification
> ----------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1180
>                 URL: http://issues.apache.org/jira/browse/XERCESJ-1180
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: DOM (Level 3 Core)
>    Affects Versions: 2.8.0
>         Environment: 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)
>            Reporter: Yury Semikhatsky
>         Assigned To: Michael Glavassevich
>             Fix For: 2.8.1
>
>
> 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)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org


[jira] Assigned: (XERCESJ-1180) Document root changes indirectly during DeferredDocumentImpl children modification

Posted by "Michael Glavassevich (JIRA)" <xe...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XERCESJ-1180?page=all ]

Michael Glavassevich reassigned XERCESJ-1180:
---------------------------------------------

    Assignee: Michael Glavassevich

> Document root changes indirectly during DeferredDocumentImpl children modification
> ----------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1180
>                 URL: http://issues.apache.org/jira/browse/XERCESJ-1180
>             Project: Xerces2-J
>          Issue Type: Bug
>         Environment: 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)
>            Reporter: Yury Semikhatsky
>         Assigned To: Michael Glavassevich
>
> 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)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org


[jira] Resolved: (XERCESJ-1180) Document root changes indirectly during DeferredDocumentImpl children modification

Posted by "Michael Glavassevich (JIRA)" <xe...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XERCESJ-1180?page=all ]

Michael Glavassevich resolved XERCESJ-1180.
-------------------------------------------

    Resolution: Fixed

There was an assumption in the code that a newly expanded element node must be the root element if none currently exists.  Your test proves that isn't always true.  I just committed a fix to SVN.  Note that you weren't actually using Xerces when you encountered this bug.  The com.sun.org.apache.xerces.internal.* classes come from Sun's implementation of JDK 5.0+ and are a fork/derivative of Apache Xerces.  If you're looking for a fix there you'll need to pursue it with Sun.

> Document root changes indirectly during DeferredDocumentImpl children modification
> ----------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1180
>                 URL: http://issues.apache.org/jira/browse/XERCESJ-1180
>             Project: Xerces2-J
>          Issue Type: Bug
>         Environment: 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)
>            Reporter: Yury Semikhatsky
>         Assigned To: Michael Glavassevich
>
> 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)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org