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

Element.setAttributeNodeNS() adds an attribute which belongs to another Element

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1fcs
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description



      Name: eaR10174 Date: 01/25/2001


         The implementation of the method org.w3c.dom.Element.setAttributeNodeNS(Attr newAttr) adds an
      attribute which belongs to another Element object. Instead of this it must throw a DOMException with
      the INUSE_ATTRIBUTE_ERR code (See test.java below).
        Definition of the method in p. 1.2 "Fundamental Interfaces" of DOM Level 2 Core
      (http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614) reads:
        " setAttributeNodeNS introduced in DOM Level 2
          ...
          Exceptions
               DOMException ...
               ...
                            INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an attribute of another Element
                            object. The DOM user must explicitly clone Attr nodes to re-use them in other
                            elements. "

        This bug appears in build jaxp-1.1ea2-b18-24_jan_2001 and affects new tests in TCK JAXP 1.1
        
           api/org_w3c_dom/Element/SetAttributeNodeNSTests.html#setAttributeNodeNSTest004
           api/org_w3c_dom/NamedNodeMap/SetNamedItemNSTests.html#setNamedItemNSTest004

      ------------------------------------test.java-----------------------------
      import org.w3c.dom.Document;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import java.io.ByteArrayInputStream;
      import org.w3c.dom.Element;
      import org.w3c.dom.Attr;
      import org.w3c.dom.DOMException;

      public class test {
          
          public static void main(String argv[]) {
              
              try {
                  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                  DocumentBuilder documentBuilder = dbf.newDocumentBuilder();


                  Document document = documentBuilder.newDocument();
                  
                  Element root1 = document.createElementNS("http://xxxx.xx/", "test:root");
                  Element root2 = document.createElementNS("http://xxxx.xx/", "test:root");
                  Attr attr = document.createAttributeNS("http://xxxx.xx/", "test:a");
              
                  root1.setAttributeNodeNS(attr);
              
                  attr = root1.getAttributeNodeNS("http://xxxx.xx/", "a");
                          
                  try {
                      root2.setAttributeNodeNS(attr);
                  
                      System.out.println("Set an attribute which had been belonged to another element.");
                  } catch (DOMException e) {
                      if (e.code == DOMException.INUSE_ATTRIBUTE_ERR) {
                          System.out.println("OKEY");
                      } else {
                          System.out.println("Unexpected error code " + e.code);
                      }
                  }
              } catch (Exception e) {
                  System.out.println("Unexpected " + e + " was thrown");
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      JAXP build version: jaxp-1.1ea2-b18-22_jan_2001

      % 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)

      OKEY
      ---------------------------------------------------------------------------
      JAXP build version: jaxp-1.1ea2-b18-24_jan_2001

      % 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)

      Set an attribute which had been belonged to another element.
      ---------------------------------------------------------------------------

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

        Attachments

          Activity

            People

            • Assignee:
              egoei Edwin Goei (Inactive)
              Reporter:
              evgsunw Evg Evg (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: