You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Ramkumar Natarajan <nr...@cs.purdue.edu> on 2000/07/13 11:27:22 UTC

Bug in DocumentImpl.cloneNode

Hi,

I am not sure if this is a bug or intentional, but the following code
fails:
//.... Parse some xml document using myParser
Document xmlDoc = myParser.getDocument();
xmlDoc = (Document) xmlDoc.cloneNode(true); // Create a deep clone
//.... Try using xmlDoc's nodes

The above code throws a null pointer exception when an attempt is made to
access the contents (Nodes) of xmlDoc after a "supposedly" deep clone.

On looking at the code for DocumentImpl.cloneNode, I found that I could
fix the problem by adding the following lines after line 248 to
DocumentImpl.java :
if (syncChildren()) {
	synchonizeChildren();
}

I think this should be the correct behaviour, but as I have no idea about
the DOM spec., I am not sure if it is.  Strangely enough, the first piece
of code works perfectly fine with xerces-j version 1.0.3.  It started
failing after I started using 1.1.1 and still fails in 1.1.2.  It would be
interesting to look at the code for DocumentImpl in 1.0.3, but I am just
too lazy.

In any case, I am attaching the version of DocumentImpl.java with the
above change.  A zillion apologies if this is just my stupidity and not an
actual "bug" :-)

cheers,
nrk.