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

REGRESSION: Problem with cloneNode()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 5.0u2
    • Component/s: xml
    • Subcomponent:
    • Resolved In Build:
      b04
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      J2SE 5.0

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Mandrake Linux

      A DESCRIPTION OF THE PROBLEM :
      Get two Nodes from a DOM. Create a third Node by cloning the first Node. Set the value of the ID attribute, of this cloned Node to that of the second Node. Now, getElemntById(IdOfFirstNode) and getElemntById(IdOfSecondNode) returns null. But in java1.4 both thesecalls returns the corresponding Nodes.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Get two Nodes from a DOM.

          sourceCableNode = document.getElementById( String.valueOf(sourceCableNo) );
          targetCableNode = document.getElementById( String.valueOf(targetCableNo) );

      2. Create a clone of the first Node

          tempCableNode = sourceCableNode.cloneNode(true);

      3. Set the value of the ID attribute, of this cloned Node to that of the second Node

          tempCableNode.getAttributes().getNamedItem("cableid").setNodeValue(
                                                                              String.valueOf(targetCableNo));
          //here, the attribute cableid is delared as ID in the DTD

      4. Now, call
          document.getElementById(String.valueOf(sourceCableNo) )
      and
          document.getElementById(String.valueOf(targetCableNo) )


       

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Both the above calls to the getElementById element should return the corresponding Nodes. So is the behaviour with java1.4
      ACTUAL -
      Both the calls
          document.getElementById( "C" + String.valueOf(sourceCableNo) )
      and
          document.getElementById( "C" + String.valueOf(targetCableNo) )
      returns null.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No relevent error messages

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      //only the method included

       public void copyCable(int sourceCableNo, int targetCableNo) throws Exception {
              Element docRoot;
              Node sourceCableNode;
              Node targetCableNode;
      Node tempCableNode;

      try {
      docRoot = document.getDocumentElement();
      sourceCableNode = document.getElementById( "C" + String.valueOf(sourceCableNo) );
      targetCableNode = document.getElementById( "C" + String.valueOf(targetCableNo) );
      tempCableNode = sourceCableNode.cloneNode(true);

      tempCableNode.getAttributes().getNamedItem("cableid").setNodeValue("C" +
           String.valueOf(targetCableNo));


      if (null != document.getElementById( "C" + String.valueOf(sourceCableNo) ) ) {
      System.out.println("4 sourceCableNode not null");
      }
      else {
      System.out.println("4 sourceCableNode is null");
      }
      if (null != document.getElementById( "C" + String.valueOf(targetCableNo) ) ) {
      System.out.println("4 targetCableNode not null");
      }
      else {
      System.out.println("4 targetCableNode is null");
      }

      docRoot.replaceChild(tempCableNode, targetCableNode);
      DateFormat date = DateFormat.getDateInstance();
      String currentDate = date.format( new Date() );
      targetCableNode = document.getElementById( "C" + String.valueOf(targetCableNo) );
      targetCableNode.getAttributes().getNamedItem("cdate").setNodeValue(currentDate);
      targetCableNode.getAttributes().getNamedItem("mdate").setNodeValue(currentDate);

        saveDOM();

      } catch (Exception e) {
      throw e;
      }
         }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Instead of cloning copy each atribute value to that of the new node.

      Release Regression From : 1.4.2
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-2-03 01:00:58 GMT

        Attachments

          Activity

            People

            Assignee:
            duke J. Duke (Inactive)
            Reporter:
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: