Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4635331

Method Node.cloneNode() incorrectly clones Attr node with children

    XMLWordPrintable

    Details

      Description



      Name: eaR10174 Date: 02/08/2002


        Method org.w3c.dom.Node.cloneNode() incorrectly clones an Attr the Attr node with
      its children when the node is cloned with parameter deep=false. The method returns
      duplicate node with children.
        The testcase consists of the steps (see test.java below):
        
        1. The Attr node is created by Document.createAttribute();
        2. The Text node is appended to it.
        3. The created node is cloned with deep=false.

        The DOM Level 2 spec
      (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247) does
      not describe how the Attr node with children is cloned. This implies that the Attr
      node with children is cloned the same way as described for general case. Namely,
      children cloning depends on the value of parameter 'deep'.
        So the duplicate node should not have any children. Also the duplicate node should
      have an empty value because the value of cloned Attr node had not explicitly set.

        This bug is found in jaxp-1.2.0-beta-b06-06_feb_2002 and affects the test in the
      JAXP 1.2 TCK.
        
        api/org_w3c/dom/Node/index.html#CloneNode[CloneNode003]

      ------------------------------------test.java-----------------------------
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.ParserConfigurationException;
      import org.w3c.dom.Node;
      import org.w3c.dom.Document;
      import org.w3c.dom.Attr;

      public class test {

          public static void main (String[] args) {
              Document document = null;
              try {
                  DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()
                      .newDocumentBuilder();
                  
                  document = docBuilder.newDocument();
              } catch (ParserConfigurationException e) {
                  e.printStackTrace();
                  System.exit(1);
              }
          
              Node node = document.createAttribute("attr");
              node.appendChild(document.createTextNode("xxx"));
          
              Attr clone = (Attr)node.cloneNode(false);

              System.out.println("Check clone...");
              System.out.println("value: " + clone.getValue());
              System.out.println("hasChildNode(): " + clone.hasChildNodes());
          }
      }
      ---------------------------------------------------------------------------
      % echo $CLASSPATH
      .:/home/evg/lib/dom.jar:/home/evg/lib/sax.jar:/home/evg/lib/jaxp-api.jar:/home/evg/lib
      /xalan.jar:/home/evg/lib/xercesImpl.jar

      % java -showversion test
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      Check clone...
      value: xxx
      hasChildNode(): true
      ---------------------------------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            duke J. Duke (Inactive)
            Reporter:
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: