Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353407 - NodeContainer.replaceChild removes a child that is replaced by itself
Summary: NodeContainer.replaceChild removes a child that is replaced by itself
Status: RESOLVED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.3.1   Edit
Assignee: Tobias Liefke CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-29 09:23 EDT by Tobias Liefke CLA
Modified: 2011-08-08 15:26 EDT (History)
1 user (show)

See Also:


Attachments
Proposed patch for the NodeContainer (916 bytes, patch)
2011-07-29 09:23 EDT, Tobias Liefke CLA
nsand.dev: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.