Buggy code:
public class CoreDocumentImpl extends ParentNode implements Document { static final long serialVersionUID = 0 ; protected DocumentTypeImpl docType ; protected ElementImpl docElement ; transient NodeListCache fFreeNLCache ; protected String encoding ; protected String actualEncoding ; protected String version ; protected boolean standalone ; protected String fDocumentURI ; protected Hashtable userData ; protected Hashtable identifiers ; transient DOMNormalizer domNormalizer = null ; transient DOMConfigurationImpl fConfiguration = null ; transient Object fXPathEvaluator = null ; private static final int [ ] kidOK ; protected int changes = 0 ; protected boolean allowGrammarAccess ; protected boolean errorChecking = true ; protected boolean xmlVersionChanged = false ; private int documentNumber = 0 ; private int nodeCounter = 0 ; private Hashtable nodeTable ; private boolean xml11Version = false ; public CoreDocumentImpl ( ) { } public CoreDocumentImpl ( boolean grammarAccess ) { } public CoreDocumentImpl ( DocumentType doctype ) { } public CoreDocumentImpl ( DocumentType doctype , boolean grammarAccess ) { } public final Document getOwnerDocument ( ) { } public short getNodeType ( ) { } public String getNodeName ( ) { } public Node cloneNode ( boolean deep ) { } protected void cloneNode ( CoreDocumentImpl newdoc , boolean deep ) { } public Node insertBefore ( Node newChild , Node refChild ) throws DOMException { } public Node removeChild ( Node oldChild ) throws DOMException { } public Node replaceChild ( Node newChild , Node oldChild ) throws DOMException { } public String getTextContent ( ) throws DOMException { } public void setTextContent ( String textContent ) throws DOMException { } public Object getFeature ( String feature , String version ) { } public Attr createAttribute ( String name ) throws DOMException { } public CDATASection createCDATASection ( String data ) throws DOMException { } public Comment createComment ( String data ) { } public DocumentFragment createDocumentFragment ( ) { } public Element createElement ( String tagName ) throws DOMException { } public EntityReference createEntityReference ( String name ) throws DOMException { } public ProcessingInstruction createProcessingInstruction ( String target , String data ) throws DOMException { } public Text createTextNode ( String data ) { } public DocumentType getDoctype ( ) { } public Element getDocumentElement ( ) { } public NodeList getElementsByTagName ( String tagname ) { } public DOMImplementation getImplementation ( ) { } public void setErrorChecking ( boolean check ) { } public void setStrictErrorChecking ( boolean check ) { } public boolean getErrorChecking ( ) { } public boolean getStrictErrorChecking ( ) { } public String getInputEncoding ( ) { } public void setInputEncoding ( String value ) { } public void setXmlEncoding ( String value ) { } public String getXmlEncoding ( ) { } public void setXmlVersion ( String value ) { } public String getXmlVersion ( ) { } public void setXmlStandalone ( boolean value ) throws DOMException { } public boolean getXmlStandalone ( ) { } public String getDocumentURI ( ) { } public Node renameNode ( Node n , String namespaceURI , String name ) throws DOMException { <START_BUG> if ( ( n . getOwnerDocument ( ) ) != ( this ) ) { <END_BUG> String msg = DOMMessageFormatter . formatMessage ( DOM_DOMAIN , "WRONG_DOCUMENT_ERR" , null ) ; throw new DOMException ( DOMException . WRONG_DOCUMENT_ERR , msg ) ; } switch ( n . getNodeType ( ) ) { case Node . ELEMENT_NODE : { ElementImpl el = ( ( ElementImpl ) ( n ) ) ; if ( el instanceof ElementNSImpl ) { ( ( ElementNSImpl ) ( el ) ) . rename ( namespaceURI , name ) ; } else { if ( namespaceURI == null ) { int colon1 = name . indexOf ( ':' ) ; if ( colon1 != ( - 1 ) ) { String msg = DOMMessageFormatter . formatMessage ( DOM_DOMAIN , "NAMESPACE_ERR" , null ) ; throw new DOMException ( DOMException . NAMESPACE_ERR , msg ) ; } if ( ( errorChecking ) && ( ! ( CoreDocumentImpl . isXMLName ( name , xml11Version ) ) ) ) { String msg = DOMMessageFormatter . formatMessage ( DOM_DOMAIN , "INVALID_CHARACTER_ERR" , null ) ; throw new DOMException ( DOMException . INVALID_CHARACTER_ERR , msg ) ; } el . rename ( name ) ; } else { ElementNSImpl nel = new ElementNSImpl ( this , namespaceURI , name ) ; copyEventListeners ( el , nel ) ; Hashtable data = removeUserDataTable ( el ) ; Node parent = el . getParentNode ( ) ; Node nextSib = el . getNextSibling ( ) ; if ( parent != null ) { parent . removeChild ( el ) ; } Node child = el . getFirstChild ( ) ; while ( child != null ) { el . removeChild ( child ) ; nel . appendChild ( child ) ; child = el . getFirstChild ( ) ; } nel . moveSpecifiedAttributes ( el ) ; setUserDataTable ( nel , data ) ; callUserDataHandlers ( el , nel , NODE_RENAMED ) ; if ( parent != null ) { parent . insertBefore ( nel , nextSib ) ; } el = nel ; } } renamedElement ( ( ( Element ) ( n ) ) , el ) ; return el ; } case Node . ATTRIBUTE_NODE : { AttrImpl at = ( ( AttrImpl ) ( n ) ) ; Element el = at . getOwnerElement ( ) ; if ( el != null ) { el . removeAttributeNode ( at ) ; } if ( n instanceof AttrNSImpl ) { ( ( AttrNSImpl ) ( at ) ) . rename ( namespaceURI , name ) ; if ( el != null ) { el . setAttributeNodeNS ( at ) ; } } else { if ( namespaceURI == null ) { at . rename ( name ) ; if ( el != null ) { el . setAttributeNode ( at ) ; } }

Fix:
if ( ( ( n . getOwnerDocument ( ) ) != ( this ) ) && ( n != ( this ) ) ) {