Buggy code:
public class DOMSerializerImpl implements DOMConfiguration , LSSerializer { private XMLSerializer serializer ; private XML11Serializer xml11Serializer ; private DOMStringList fRecognizedParameters ; protected short features = 0 ; protected static final short NAMESPACES = 1 << 0 ; protected static final short WELLFORMED = 1 << 1 ; protected static final short ENTITIES = 1 << 2 ; protected static final short CDATA = 1 << 3 ; protected static final short SPLITCDATA = 1 << 4 ; protected static final short COMMENTS = 1 << 5 ; protected static final short DISCARDDEFAULT = 1 << 6 ; protected static final short INFOSET = 1 << 7 ; protected static final short XMLDECL = 1 << 8 ; protected static final short NSDECL = 1 << 9 ; protected static final short DOM_ELEMENT_CONTENT_WHITESPACE = 1 << 10 ; private DOMErrorHandler fErrorHandler = null ; private final DOMErrorImpl fError = new DOMErrorImpl ( ) ; private final DOMLocatorImpl fLocator = new DOMLocatorImpl ( ) ; private static final RuntimeException abort = new RuntimeException ( ) ; public DOMSerializerImpl ( ) { } public DOMConfiguration getDomConfig ( ) { } public void setParameter ( String name , Object value ) throws DOMException { } public boolean canSetParameter ( String name , Object state ) { } public DOMStringList getParameterNames ( ) { } public Object getParameter ( String name ) throws DOMException { } public String writeToString ( Node wnode ) throws DOMException , LSException { } public void setNewLine ( String newLine ) { } public String getNewLine ( ) { } public LSSerializerFilter getFilter ( ) { } public void setFilter ( LSSerializerFilter filter ) { } private void initSerializer ( XMLSerializer ser ) { } private void copySettings ( XMLSerializer src , XMLSerializer dest ) { } public boolean write ( Node node , LSOutput destination ) throws LSException { } public boolean writeToURI ( Node node , String URI ) throws LSException { } private void prepareForSerialization ( XMLSerializer ser , Node node ) { ser . reset ( ) ; ser . features = features ; ser . fDOMErrorHandler = fErrorHandler ; ser . fNamespaces = ( ( features ) & ( DOMSerializerImpl . NAMESPACES ) ) != 0 ; ser . fNamespacePrefixes = ( ( features ) & ( DOMSerializerImpl . NSDECL ) ) != 0 ; ser . _format . setOmitComments ( ( ( ( features ) & ( DOMSerializerImpl . COMMENTS ) ) == 0 ) ) ; ser . _format . setOmitXMLDeclaration ( ( ( ( features ) & ( DOMSerializerImpl . XMLDECL ) ) == 0 ) ) ; if ( ( ( features ) & ( DOMSerializerImpl . WELLFORMED ) ) != 0 ) { Node next ; Node root ; root = node ; Method versionChanged ; boolean verifyNames = true ; Document document = ( ( node . getNodeType ( ) ) == ( Node . DOCUMENT_NODE ) ) ? ( ( Document ) ( node ) ) : node . getOwnerDocument ( ) ; try { versionChanged = document . getClass ( ) . getMethod ( "isXMLVersionChanged()" , new Class [ ] { } ) ; if ( versionChanged != null ) { verifyNames = ( ( Boolean ) ( versionChanged . invoke ( document , ( ( Object [ ] ) ( null ) ) ) ) ) . booleanValue ( ) ; } } catch ( Exception e ) { } while ( node != null ) { verify ( node , verifyNames , false ) ; next = node . getFirstChild ( ) ; while ( next == null ) { next = node . getNextSibling ( ) ; if ( next == null ) { node = node . getParentNode ( ) ; <START_BUG> if ( root == node ) { <END_BUG> next = null ; break ; } next = node . getNextSibling ( ) ; } } node = next ; } } } private void verify ( Node node , boolean verifyNames , boolean xml11Version ) { } }

Fix:
if ( ( node == null ) || ( root == node ) ) {