Buggy code:
LSInput in = impl . createLSInput ( ) ; in . setCharacterStream ( r ) ; doc = builder . parse ( in ) ; root = doc . getDocumentElement ( ) ; child1 = ( ( Element ) ( root . getFirstChild ( ) ) ) ; child2 = ( ( Element ) ( child1 . getNextSibling ( ) ) ) ; child3 = ( ( Element ) ( child2 . getNextSibling ( ) ) ) ; String name = root . getNodeName ( ) ; Assertion . verify ( name . equals ( "xsl:stylesheet" ) , "xsl:stylesheet" ) ; String value = root . getAttributeNS ( "http:////www.w3.org//2000//xmlns//" , "xsl" ) ; Assertion . verify ( ( value != null ) , "xmlns:xsl<seq2seq4repair_space>!=<seq2seq4repair_space>null" ) ; Assertion . verify ( value . equals ( "http:////www.w3.org//1999//XSL//Transform" ) , ( "xmlns:xsl=" + value ) ) ; value = root . getAttributeNS ( "http:////www.w3.org//2000//xmlns//" , "NS1" ) ; Assertion . verify ( ( ( value != null ) && ( value . equals ( "http:////attr1" ) ) ) , ( "xmlns:NS1=" + value ) ) ; Assertion . verify ( child1 . getNodeName ( ) . equals ( "NS2:child1" ) , "NS2:child1" ) ; value = child1 . getAttributeNS ( "http:////www.w3.org//2000//xmlns//" , "NS2" ) ; Assertion . verify ( ( ( value != null ) && ( value . equals ( "http:////child1" ) ) ) , ( "xmlns:NS2=" + value ) ) ; value = child1 . getAttributeNS ( "http:////www.w3.org//2000//xmlns//" , "NS1" ) ; Assertion . verify ( ( ( value != null ) && ( value . equals ( "http:////attr2" ) ) ) , ( "xmlns:NS1=" + value ) ) ; Assertion . verify ( child3 . getNodeName ( ) . equals ( "xsl:child3" ) , "xsl:child3" ) ; value = child3 . getAttributeNS ( "http:////www.w3.org//2000//xmlns//" , "NS1" ) ; Assertion . verify ( ( ( value != null ) && ( value . equals ( "http:////a2" ) ) ) , ( "xmlns:NS1=" + value ) ) ; value = child3 . getAttributeNS ( "http:////www.w3.org//2000//xmlns//" , "a1" ) ; Assertion . verify ( ( ( value != null ) && ( value . equals ( "http:////a1" ) ) ) , ( "xmlns:a1=" + value ) ) ; value = child3 . getAttributeNS ( "http:////www.w3.org//2000//xmlns//" , "xsl" ) ; Assertion . verify ( ( ( value != null ) && ( value . equals ( "http:////www.w3.org//1999//XSL//Transform" ) ) ) , ( "xmlns:xsl=" + value ) ) ; Attr attr = child3 . getAttributeNodeNS ( "http:////a2" , "attr2" ) ; Assertion . verify ( ( attr != null ) , "NS6:attr2<seq2seq4repair_space>!=null" ) ; Assertion . verify ( ( ( child3 . getAttributes ( ) . getLength ( ) ) == 5 ) , "xsl:child3<seq2seq4repair_space>has<seq2seq4repair_space>5<seq2seq4repair_space>attrs" ) ; } { config = builder . getDomConfig ( ) ; config . setParameter ( "error-handler" , Test . errorHandler ) ; config . setParameter ( "validate" , Boolean . FALSE ) ; config . setParameter ( "entities" , Boolean . TRUE ) ; DocumentImpl doc = ( ( DocumentImpl ) ( builder . parseURI ( "tests//dom//dom3//wholeText.xml" ) ) ) ; Element root = doc . getDocumentElement ( ) ; Element test = ( ( Element ) ( doc . getElementsByTagName ( "elem" ) . item ( 0 ) ) ) ; test . appendChild ( doc . createTextNode ( "Address:<seq2seq4repair_space>" ) ) ; test . appendChild ( doc . createEntityReference ( "ent2" ) ) ; test . appendChild ( doc . createTextNode ( "City:<seq2seq4repair_space>" ) ) ; test . appendChild ( doc . createEntityReference ( "ent1" ) ) ; DocumentType doctype = doc . getDoctype ( ) ; Node entity = doctype . getEntities ( ) . getNamedItem ( "ent3" ) ; NodeList ls = test . getChildNodes ( ) ; Assertion . verify ( ( ( ls . getLength ( ) ) == 5 ) , "List<seq2seq4repair_space>length" ) ; String compare1 = "Home<seq2seq4repair_space>Address:<seq2seq4repair_space>1900<seq2seq4repair_space>Dallas<seq2seq4repair_space>Road<seq2seq4repair_space>(East)<seq2seq4repair_space>City:<seq2seq4repair_space>Dallas.<seq2seq4repair_space>California.<seq2seq4repair_space>USA<seq2seq4repair_space>PO<seq2seq4repair_space>#5668" ; Assertion . verify ( ( ( TextImpl ) ( ls . item ( 0 ) ) ) . getWholeText ( ) . equals ( compare1 ) , "Compare1" ) ; <START_BUG> String compare2 = "Address:<seq2seq4repair_space>1900<seq2seq4repair_space>Dallas<seq2seq4repair_space>Road<seq2seq4repair_space>(East)<seq2seq4repair_space>City:<seq2seq4repair_space>Dallas.<seq2seq4repair_space>California.<seq2seq4repair_space>USA<seq2seq4repair_space>PO<seq2seq4repair_space>#5668" ; <END_BUG> Assertion . verify ( ( ( TextImpl ) ( ls . item ( 1 ) ) ) . getWholeText ( ) . equals ( compare2 ) , "Compare2" ) ; ( ( NodeImpl ) ( ls . item ( 0 ) ) ) . setReadOnly ( true , true ) ; TextImpl original = ( ( TextImpl ) ( ls . item ( 0 ) ) ) ; Node newNode = original . replaceWholeText ( "Replace<seq2seq4repair_space>with<seq2seq4repair_space>this<seq2seq4repair_space>text" ) ; ls = test . getChildNodes ( ) ; Assertion . verify ( ( ( ls . getLength ( ) ) == 1 ) , "Length<seq2seq4repair_space>==<seq2seq4repair_space>1" ) ; Assertion . verify ( ls . item ( 0 ) . getNodeValue ( ) . equals ( "Replace<seq2seq4repair_space>with<seq2seq4repair_space>this<seq2seq4repair_space>text" ) , "Replacement<seq2seq4repair_space>works" ) ; Assertion . verify ( ( newNode != original ) , "New<seq2seq4repair_space>node<seq2seq4repair_space>created" ) ; Text text = doc . createTextNode ( "readonly" ) ; ( ( NodeImpl ) ( text ) ) . setReadOnly ( true , true ) ; text = ( ( TextImpl ) ( text ) ) . replaceWholeText ( "Data" ) ; Assertion . verify ( text . getNodeValue ( ) . equals ( "Data" ) , "New<seq2seq4repair_space>value<seq2seq4repair_space>'Data'" ) ; test = ( ( Element ) ( doc . getElementsByTagName ( "elem" ) . item ( 1 ) ) ) ; try { ( ( TextImpl ) ( test . getFirstChild ( ) ) ) . replaceWholeText ( "can't<seq2seq4repair_space>replace" ) ; } catch ( DOMException e ) { Assertion . verify ( ( e != null ) ) ; } String compare3 = "Test:<seq2seq4repair_space>The<seq2seq4repair_space>Content<seq2seq4repair_space>ends<seq2seq4repair_space>here.<seq2seq4repair_space>" ; } { Test . errorCounter = 0 ; config = builder . getDomConfig ( ) ; config . setParameter ( "error-handler" , Test . errorHandler ) ; config . setParameter ( "resource-resolver" , Test . resolver ) ;

Fix:
String compare2 = "Home<seq2seq4repair_space>Address:<seq2seq4repair_space>1900<seq2seq4repair_space>Dallas<seq2seq4repair_space>Road<seq2seq4repair_space>(East)<seq2seq4repair_space>City:<seq2seq4repair_space>Dallas.<seq2seq4repair_space>California.<seq2seq4repair_space>USA<seq2seq4repair_space>PO<seq2seq4repair_space>#5668" ;