Axis
  1. Axis
  2. AXIS-2347

setBody results in a DOMException

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.3
    • Fix Version/s: None
    • Component/s: SAAJ
    • Labels:
      None

      Description

      The act of detaching the body of a soap envelope and trying to set its body with a new soap body results in following Exception

      javax.xml.soap.SOAPException: javax.xml.soap.SOAPException: org.w3c.dom.DOMExcep
      tion: NodeImpl Not found
      at org.apache.axis.message.SOAPBody.setParentElement(SOAPBody.java :91)
      at org.apache.axis.message.SOAPEnvelope.setBody(SOAPEnvelope.java:309)
      at mytest.soapenvelope.TestSOAPEnvelope.setBody(TestSOAPEnvelope.java:16
      )
      at mytest.soapenvelope.TestSOAPEnvelope.main (TestSOAPEnvelope.java:40)
      Caused by: javax.xml.soap.SOAPException: org.w3c.dom.DOMException: NodeImpl Not
      found
      at org.apache.axis.message.NodeImpl.setParentElement(NodeImpl.java:634)
      at org.apache.axis.message.SOAPBody.setParentElement (SOAPBody.java:88)
      ... 3 more
      Caused by: org.w3c.dom.DOMException: NodeImpl Not found
      at org.apache.axis.message.NodeImpl.removeChild(NodeImpl.java:515)
      at org.apache.axis.message.SOAPEnvelope.removeChild (SOAPEnvelope.java:61
      7)
      at org.apache.axis.message.NodeImpl.detachNode(NodeImpl.java:661)
      at org.apache.axis.message.NodeImpl.appendChild(NodeImpl.java:493)
      at org.apache.axis.message.NodeImpl.setParent (NodeImpl.java:792)
      at org.apache.axis.message.NodeImpl.setParentElement(NodeImpl.java:632)
      ... 4 more

      Attached test case (TestSOAPEnvelope.java) describes the scenario.

      1. TestSOAPEnvelope.java
        2 kB
        Jayachandra Sekhara Rao Sunkara
      2. NodeImpl_setParent.patch
        0.4 kB
        Jayachandra Sekhara Rao Sunkara

        Issue Links

          Activity

          Hide
          Jayachandra Sekhara Rao Sunkara added a comment -

          attaching suggested patch in a diff format.

          Show
          Jayachandra Sekhara Rao Sunkara added a comment - attaching suggested patch in a diff format.
          Hide
          Jayachandra Sekhara Rao Sunkara added a comment -

          When I delved inside the source, I realized that the problem is cropping up because of logic inside NodeImpl.setParent(...) method. Here is the explanation and a suggested patch.

          *******
          The current NodeImpl.setParent() code looks like follows...

          ln 1 /**
          ln 2 * Set the parent node and invoke appendChild(this) to
          ln 3 * add this node to the parent's list of children.
          ln 4 * @param parent
          ln 5 * @throws SOAPException
          ln 6 */
          ln 7 protected void setParent(NodeImpl parent) throws SOAPException {
          ln 8 if (this.parent == parent)

          { ln 9 return; ln 10 }

          ln 11 if (this.parent != null)

          { ln 12 this.parent.removeChild(this); ln 13 }

          ln 14 if (parent != null)

          { ln 15 parent.appendChild(this); ln 16 }

          ln 17 this.setDirty();
          ln 18 this.parent = parent;
          ln 19 }

          There is a sly bug in this code. At line 12 <code>this</code> (lets denote it as NODE_C) node is removed as a child from its existing parent (lets call this parent as NODE_P) but the link of NODE_C.parent still points to NODE_P. Because of this later when <code>appendChild</code> method is called at ln15 with NODE_C sent as the parameter, within the code of appendChild since there is going to be a detachNode call on NODE_C that call is going to fail as NODE_C claims it has a non-null parent (NODE_P) but NODE_P list of children list doesn't contain NODE_C.
          So I'm suggesting the following patch

          ln 11 if (this.parent != null)

          { ln 12 this.parent.removeChild(this); ln 12a this.parent = null; //remove all old lineage traces from both sides ln 12b //so that future appendChild()/detachNode() doesn't crib ln 13 }

          *********

          I've tested the patch and found that it doesn't break any existing scenarios. I'll check this in EOD today unless someone has any objection.

          Show
          Jayachandra Sekhara Rao Sunkara added a comment - When I delved inside the source, I realized that the problem is cropping up because of logic inside NodeImpl.setParent(...) method. Here is the explanation and a suggested patch. ******* The current NodeImpl.setParent() code looks like follows... ln 1 /** ln 2 * Set the parent node and invoke appendChild(this) to ln 3 * add this node to the parent's list of children. ln 4 * @param parent ln 5 * @throws SOAPException ln 6 */ ln 7 protected void setParent(NodeImpl parent) throws SOAPException { ln 8 if (this.parent == parent) { ln 9 return; ln 10 } ln 11 if (this.parent != null) { ln 12 this.parent.removeChild(this); ln 13 } ln 14 if (parent != null) { ln 15 parent.appendChild(this); ln 16 } ln 17 this.setDirty(); ln 18 this.parent = parent; ln 19 } There is a sly bug in this code. At line 12 <code>this</code> (lets denote it as NODE_C) node is removed as a child from its existing parent (lets call this parent as NODE_P) but the link of NODE_C.parent still points to NODE_P. Because of this later when <code>appendChild</code> method is called at ln15 with NODE_C sent as the parameter, within the code of appendChild since there is going to be a detachNode call on NODE_C that call is going to fail as NODE_C claims it has a non-null parent (NODE_P) but NODE_P list of children list doesn't contain NODE_C. So I'm suggesting the following patch ln 11 if (this.parent != null) { ln 12 this.parent.removeChild(this); ln 12a this.parent = null; //remove all old lineage traces from both sides ln 12b //so that future appendChild()/detachNode() doesn't crib ln 13 } ********* I've tested the patch and found that it doesn't break any existing scenarios. I'll check this in EOD today unless someone has any objection.
          Hide
          Jayachandra Sekhara Rao Sunkara added a comment -

          Attaching TestSOAPEnvelope.java that depicts the scenario when the described exception is produced.

          Show
          Jayachandra Sekhara Rao Sunkara added a comment - Attaching TestSOAPEnvelope.java that depicts the scenario when the described exception is produced.

            People

            • Assignee:
              Jayachandra Sekhara Rao Sunkara
              Reporter:
              Jayachandra Sekhara Rao Sunkara
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development