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

NamedNodeMap.setNamedItemNS() allows to add a node created by another document

    Details

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

      Description



      Name: inR10064 Date: 12/13/2000



        JAXP 1.1 method org.w3c.dom.NamedNodeMap.setNamedItemNS(Node arg) doesn't throw
      DOMException with WRONG_DOCUMENT_ERR code when it is used to add a node created by another
      document (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-1780488922) reads:

      " setNamedItemNS introduced in DOM Level 2
           ....
           Exceptions
           DOMException WRONG_DOCUMENT_ERR: Raised if arg was created from a different
                        document than the one that created this map. "

      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/NamedNodeMap/SetNamedItemNSTests.html#setNamedItemNSTest003

      ------------------------------------test.java-----------------------------
      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
      import org.w3c.dom.Attr;
      import org.w3c.dom.DOMException;
      import org.w3c.dom.NamedNodeMap;
      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 document1 = documentBuilder.newDocument();
                  Document document2 = documentBuilder.newDocument();

                  Element root = document1.createElementNS("http://xxxx.xx/",
                                                           "test:root");
                  Attr attr = document2.createAttributeNS("http://xxxx.xx/", "test:a");
              
                  NamedNodeMap nodeMap = root.getAttributes();
                  
                  nodeMap.setNamedItemNS(attr);
                  
                  System.out.println("Could set a named item created by another document.");
              } catch (DOMException e) {
                  if (e.code == DOMException.WRONG_DOCUMENT_ERR) {
                      System.out.println("OKEY");
                  } else {
                      System.out.println("Unexpected error code " + e.code);
                  }
              } 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)

      Could set a named item created by another document.
      ---------------------------------------------------------------------------

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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: