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

Documnet.adoptNode() does not call user data handler

XMLWordPrintable

    • b49
    • generic
    • generic
    • Verified

      Name: erR10175 Date: 12/10/2003


       
          The method org.w3c.dom.Document.adoptNode(Node source)
      does not call the user data handler associated with the element being adopted.

      The documentation of the field org.w3c.dom.UserDataHandler.NODE_ADOPTED reads:

      "The node is adopted, using Node.adoptNode()."

      This wording is understood as follows: If the adoption succeeds the method
      Document.adoptNode() (Node has no such method, it's a mistake) calls a user
      data handler method

      UserDataHandler.handle(short operation, String key, Object data,
                             Node src, Node dst)

      with the operation parameter set to UserDataHandler.NODE_ADOPTED. So the
      test (see below) expects that the handler is called or the adoption fails,
      otherwise the test reports an error.

      This bug affects new test in JCK 1.5 (not integrated yet)
         api/org_w3c/dom/Document/index.html#AdoptNode[AdoptNode018]

      The bug is found in jdk1.5.0/beta/b30.

      To reproduce the bug compile and run test.java as shown in the log below:
      ------------------------------------------ test.java
      import org.w3c.dom.Node;
      import org.w3c.dom.Element;
      import org.w3c.dom.Document;
      import org.w3c.dom.UserDataHandler;
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;

      class test {
          static boolean called;

          public static void main(String [] args) throws Exception {

              UserDataHandler handler = new UserDataHandler() {
                  public void handle(short operation, String key,
                                     Object data, Node src, Node dst) {
                      if (key != null
                       && operation == UserDataHandler.NODE_ADOPTED) {
                          called = true;
                      }
                  }
              };

              DocumentBuilder docBuilder
                  = DocumentBuilderFactory.newInstance().newDocumentBuilder();

              Document firstDoc = docBuilder.newDocument();
              Document secondDoc = docBuilder.newDocument();

              Element adoptedElem = secondDoc.createElement("root");

              adoptedElem.setUserData("comment"
                  , "user data of the element", handler);

              firstDoc.adoptNode(adoptedElem);
              if (null != firstDoc.adoptNode(adoptedElem) && !called) {
                  System.out.println("the user data handler has not been called");
              } else {
                  System.out.println("OK");
              }
          }
      }
      ----------------------------------------------------

      ------------------------------------------------ log
      $javac test.java && java -cp . -showversion test
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b30)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b30, mixed mode)

      the user data handler has not been called
      ----------------------------------------------------

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

            vkorcl Venugopal K (Inactive)
            reysunw Rey Rey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: