Issue Details (XML | Word | Printable)

Key: AXIS-2347
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Jayachandra Sekhara Rao Sunkara
Reporter: Jayachandra Sekhara Rao Sunkara
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Axis

setBody results in a DOMException

Created: 20/Dec/05 02:49 PM   Updated: 20/Dec/05 04:38 PM
Return to search
Component/s: SAAJ
Affects Version/s: 1.3
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works NodeImpl_setParent.patch 2005-12-20 04:38 PM Jayachandra Sekhara Rao Sunkara 0.4 kB
Java Source File Licensed for inclusion in ASF works TestSOAPEnvelope.java 2005-12-20 02:51 PM Jayachandra Sekhara Rao Sunkara 2 kB


 Description  « Hide
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.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jayachandra Sekhara Rao Sunkara added a comment - 20/Dec/05 02:51 PM
Attaching TestSOAPEnvelope.java that depicts the scenario when the described exception is produced.

Jayachandra Sekhara Rao Sunkara added a comment - 20/Dec/05 04:35 PM
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.

Jayachandra Sekhara Rao Sunkara added a comment - 20/Dec/05 04:38 PM
attaching suggested patch in a diff format.