-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.1
-
sparc
-
solaris_7
Name: inR10064 Date: 12/15/2000
In JAXP 1.1 when another document created child is appended to org.w3c.dom.Entity,
method appendChild() throws DOMException with HIERARCHY_REQUEST_ERR code instead of
WRONG_DOCUMENT_ERR code (See test.java below).
Definition of the method org.w3c.dom.Node.appendChild() in p. 1.2 "Fundamental
Interfaces" of DOM Level 2 Core
(http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247) reads:
" appendChild
....
Exceptions
DOMException
....
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different
document than the one that created this node. "
This bug is found in builds jaxp-1.1ea-b07, jaxp-1.1ea-b08, jaxp-1.1ea-b09,
jaxp-1.1ea2-b10, jaxp-1.1ea2-b11, jaxp-1.1ea2-b12, jaxp-1.1ea2-b13, jaxp-1.1ea2-b14,
jaxp-1.1ea2-b15 and affects the new test in TCK JAXP 1.1:
api/org_w3c_dom/Node/AppendChildTests.html#appendChildTest010
------------------------------------test.java-----------------------------
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.DOMException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.io.ByteArrayInputStream;
public class test {
public static void main(String argv[]) {
try {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
String data =
"<?xml version=\"1.0\" ?>" +
"<!DOCTYPE root [" +
"<!ELEMENT root ANY>" +
"<!ENTITY ent \"foo\">" +
"]>" +
"<root/>";
ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());
Document document = documentBuilder.parse(in);
Node entity = document.getDoctype().getEntities().item(0);
/* element created by another document */
Node child = documentBuilder.newDocument().createElement("child");
entity.appendChild(child);
} catch (DOMException e) {
System.out.println("WRONG_DOCUMENT_ERR = " +
DOMException.WRONG_DOCUMENT_ERR);
System.out.println("HIERARCHY_REQUEST_ERR = " +
DOMException.HIERARCHY_REQUEST_ERR);
System.out.println("Error code: " + e.code);
} catch (Exception e) {
e.printStackTrace();
}
}
}
---------------------------------------------------------------------------
---------------------------------------------------------------------------
% java -showversion -cp .:jaxp1.1ea/jaxp.jar:jaxp1.1ea/crimson.jar test
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)
WRONG_DOCUMENT_ERR = 4
HIERARCHY_REQUEST_ERR = 3
Error code: 3
---------------------------------------------------------------------------
======================================================================