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

Element.setAttributeNodeNS() returns null instead of replaced Attr node

XMLWordPrintable

    • 1.1fcs
    • sparc
    • solaris_7
    • Verified



      Name: inR10064 Date: 12/13/2000



        When JAXP 1.1 method org.w3c.dom.Element.setAttributeNodeNS(Attr newAttr) is used
      to add a new attribute to the element which has an attribute with same local name
      and namespace URI, it returns null instead of replaced Attr node (See test.java
      below) as described in definition of the method in p. 1.2 "Fundamental Interfaces"
      of DOM Level 2 Core
      (http://www.w3.org/TR/2000/PR-DOM-Level-2-Core-20000927/core.html#ID-745549614).

      " setAttributeNodeNS introduced in DOM Level 2
             Adds a new attribute. If an attribute with that local name and that namespace
             URI is already present in the element, it is replaced by the new one.
             HTML-only DOM implementations do not need to implement this method.
             
             Parameters
             newAttr of type Attr
                 The Attr node to add to the attribute list.
             Return Value
                 Attr
                 If the newAttr attribute replaces an existing attribute with the same
                 local name and namespace URI, the replaced Attr node is returned,
                 otherwise null is returned. "

      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
      and affects the new test in TCK JAXP 1.1

      api/org_w3c_dom/Element/SetAttributeNodeNSTests.html#setAttributeNodeNSTest002

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

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

                  Document document = documentBuilder.newDocument();

                  Element root = document.createElementNS("http://xxxx.xx/", "test:root");
                  Attr attr1 = document.createAttributeNS("http://xxxx.xx/", "test:a");
              
                  root.setAttributeNodeNS(attr1);
              
                  Attr attr2 = document.createAttributeNS("http://xxxx.xx/", "test1:a");
              
                  Attr attr = root.setAttributeNodeNS(attr2);
                  
                  System.out.println("Returned value: " + attr);
              } catch (Exception e) {
                  e.printStackTrace();
                  System.out.println("Unexpected exception: " + e);
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % 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)

      Returned value: null
      ---------------------------------------------------------------------------

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

            busersunw Btplusnull User (Inactive)
            inevsunw Inev Inev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: