Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353407

Summary: NodeContainer.replaceChild removes a child that is replaced by itself
Product: [WebTools] WTP Source Editing Reporter: Tobias Liefke <eclipse>
Component: wst.xmlAssignee: Tobias Liefke <eclipse>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: normal    
Priority: P3 CC: nsand.dev
Version: 3.3   
Target Milestone: 3.3.1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed patch for the NodeContainer nsand.dev: iplog+

Description Tobias Liefke CLA 2011-07-29 09:23:07 EDT
Created attachment 200591 [details]
Proposed patch for the NodeContainer

When calling 
  org.w3c.dom.Node node, child;
  node.replaceChild(child, child);
I would expect that the result is the same DOM as before.

But as the JavaDoc for org.w3c.dom.Node.replaceChild(Node, Node) says:
"Replacing a node with itself is implementation dependent."
I would at least expect an exception then.

The org.eclipse.wst.xml.core.internal.document.NodeContainer.replaceChild(Node, Node) implementation does something totally different: it removes the given node.

From my point of view, it should make an identity check before any modification.
Comment 1 Nick Sandonato CLA 2011-08-08 15:25:54 EDT
Thanks for your patch, Tobias. Looks great! I've added a unit test to go along with the fix and released the code.