Buggy code:
static final String [ ] rangeInsertResult = new String [ ] { "<P>Abcd<seq2seq4repair_space>efgh<seq2seq4repair_space>INSERTED<seq2seq4repair_space>TEXTXY<seq2seq4repair_space>blah<seq2seq4repair_space>ijkl<//P>" , "<P>Abcd<seq2seq4repair_space>efgh<seq2seq4repair_space>XINSERTED<seq2seq4repair_space>TEXTY<seq2seq4repair_space>blah<seq2seq4repair_space>ijkl<//P>" , "<P>Abcd<seq2seq4repair_space>efgh<seq2seq4repair_space>XYINSERTED<seq2seq4repair_space>TEXT<seq2seq4repair_space>blah<seq2seq4repair_space>ijkl<//P>" , "<P>Abcd<seq2seq4repair_space>efgh<seq2seq4repair_space>XY<seq2seq4repair_space>blahINSERTED<seq2seq4repair_space>TEXT<seq2seq4repair_space>ijkl<//P>" } ; public static void main ( String [ ] args ) { } private static void printUsage ( ) { } public Test ( String arg ) { } public boolean performTest ( String arg ) { boolean passed = true ; try { DOMWriter writer = new DOMWriter ( false ) ; DOMParser parser = new DOMParser ( ) ; if ( ( ! ( arg . equals ( "delete2" ) ) ) && ( ! ( arg . equals ( "insert2" ) ) ) ) { System . out . println ( ( ( "\n***************<seq2seq4repair_space>Test<seq2seq4repair_space>==<seq2seq4repair_space>" + arg ) + "<seq2seq4repair_space>***************" ) ) ; for ( int i = 0 ; i < ( Test . tests . length ) ; i ++ ) { System . out . println ( ( ( "\n\nTest[" + i ) + "]" ) ) ; System . out . println ( ( ( ( ( "\nBefore<seq2seq4repair_space>" + arg ) + ":<seq2seq4repair_space>document=" ) + ( Test . tests [ i ] ) ) + ":" ) ) ; parser . parse ( new InputSource ( new StringReader ( Test . tests [ i ] ) ) ) ; DocumentImpl document = ( ( DocumentImpl ) ( parser . getDocument ( ) ) ) ; Range range = document . createRange ( ) ; Node root = document . getDocumentElement ( ) ; boolean surround = false ; Node surroundNode = document . createElement ( Test . SURROUND ) ; if ( arg . equals ( "surround" ) ) { surround = true ; } if ( i == 0 ) { range . setStart ( root . getFirstChild ( ) , 1 ) ; range . setEndBefore ( root . getLastChild ( ) ) ; if ( surround ) range . setEnd ( root . getLastChild ( ) , 1 ) ; } else if ( i == 1 ) { Node n1 = root . getFirstChild ( ) . getNextSibling ( ) . getFirstChild ( ) ; range . setStart ( n1 , 1 ) ; range . setEnd ( root . getLastChild ( ) , 1 ) ; if ( surround ) range . setEnd ( n1 , 2 ) ; } else if ( i == 2 ) { range . setStart ( root . getFirstChild ( ) , 1 ) ; Node n2 = root . getFirstChild ( ) . getNextSibling ( ) . getFirstChild ( ) ; range . setEnd ( n2 , 1 ) ; if ( surround ) range . setEndBefore ( root . getLastChild ( ) ) ; } else if ( i == 3 ) { Node n3 = root . getFirstChild ( ) . getFirstChild ( ) ; range . setStart ( n3 , 1 ) ; range . setEnd ( root . getLastChild ( ) . getFirstChild ( ) , 1 ) ; if ( surround ) { range . selectNode ( root . getFirstChild ( ) . getNextSibling ( ) ) ; } } else if ( i == 4 ) { Node n4 = root . getFirstChild ( ) . getFirstChild ( ) . getNextSibling ( ) . getFirstChild ( ) ; range . setStartAfter ( n4 ) ; range . setEndAfter ( root . getLastChild ( ) . getFirstChild ( ) ) ; if ( surround ) { range . selectNodeContents ( root . getFirstChild ( ) . getNextSibling ( ) ) ; } } System . out . println ( ( "range.toString=" + ( range . toString ( ) ) ) ) ; DocumentFragment frag = null ; if ( arg . equals ( "surround" ) ) { try { System . out . println ( ( "surroundNode=" + surroundNode ) ) ; range . surroundContents ( surroundNode ) ; <START_BUG> } catch ( org . w3c . dom . range e ) { <END_BUG> System . out . println ( e ) ; } String result = toString ( document ) ; System . out . println ( ( ( "After<seq2seq4repair_space>surround:<seq2seq4repair_space>document=" + result ) + ":" ) ) ; if ( ! ( result . equals ( Test . surroundResult [ i ] ) ) ) { System . out . println ( ( ( "Should<seq2seq4repair_space>be:<seq2seq4repair_space>document=" + ( Test . surroundResult [ i ] ) ) + ":" ) ) ; passed = false ; System . out . println ( "Test<seq2seq4repair_space>FAILED!" ) ; System . out . println ( ( ( "***<seq2seq4repair_space>Surround<seq2seq4repair_space>document<seq2seq4repair_space>Test[" + i ) + "]<seq2seq4repair_space>FAILED!" ) ) ; } } if ( arg . equals ( "insert" ) ) { range . insertNode ( document . createTextNode ( Test . INSERT ) ) ; String result = toString ( document ) ; System . out . println ( ( ( "After<seq2seq4repair_space>insert:<seq2seq4repair_space>document=" + result ) + ":" ) ) ; if ( ! ( result . equals ( Test . insertResult [ i ] ) ) ) { System . out . println ( ( ( "Should<seq2seq4repair_space>be:<seq2seq4repair_space>document=" + ( Test . insertResult [ i ] ) ) + ":" ) ) ; passed = false ; System . out . println ( "Test<seq2seq4repair_space>FAILED!" ) ; System . out . println ( ( ( "***<seq2seq4repair_space>Insert<seq2seq4repair_space>document<seq2seq4repair_space>Test[" + i ) + "]<seq2seq4repair_space>FAILED!" ) ) ; } } else if ( arg . equals ( "delete" ) ) { range . deleteContents ( ) ; String result = toString ( document ) ; System . out . println ( ( ( "After<seq2seq4repair_space>delete:" + result ) + ":" ) ) ; if ( ! ( result . equals ( Test . deleteResult [ i ] ) ) ) { System . out . println ( ( ( "Should<seq2seq4repair_space>be:<seq2seq4repair_space>document=" + ( Test . deleteResult [ i ] ) ) + ":" ) ) ; passed = false ; System . out . println ( "Test<seq2seq4repair_space>FAILED!" ) ;

Fix:
} catch ( RangeException e ) {