Buggy code:
public class TreeClientCallback implements ClientCallback { private Node nativeNode ; public TreeClientCallback ( Node nativeNode ) { } @ Override public void onConnected ( ClientDTO dto , Document document , boolean updateUI ) { } @ Override public void onDisconnected ( ) { } @ Override public void onExecute ( Message receivedMessage ) { log . fine ( ( "Executing<seq2seq4repair_space>received:<seq2seq4repair_space>" + receivedMessage ) ) ; log . fine ( ( "Native<seq2seq4repair_space>node<seq2seq4repair_space>is<seq2seq4repair_space>before:<seq2seq4repair_space>" + ( Element . as ( nativeNode ) . getString ( ) ) ) ) ; TreeOperation operation = ( ( TreeOperation ) ( receivedMessage . getOperation ( ) ) ) ; final int position = operation . getPosition ( ) ; final int [ ] path = operation . getPath ( ) ; final Node targetNode = TreeHelper . getChildNodeFromLocator ( nativeNode , path ) ; final short targetNodeType = targetNode . getNodeType ( ) ; if ( operation instanceof TreeInsertText ) { TreeInsertText insertText = ( ( TreeInsertText ) ( operation ) ) ; String txt = String . valueOf ( insertText . getText ( ) ) ; if ( ( Node . ELEMENT_NODE ) == targetNodeType ) { Node newTextNode = Document . get ( ) . createTextNode ( txt ) ; Node node = targetNode . getChild ( position ) ; targetNode . insertBefore ( newTextNode , node ) ; } else if ( ( Node . TEXT_NODE ) == targetNodeType ) { Text . as ( targetNode ) . insertData ( position , txt ) ; } } else if ( operation instanceof TreeDeleteText ) { TreeDeleteText deleteText = ( ( TreeDeleteText ) ( operation ) ) ; if ( ( Node . TEXT_NODE ) == targetNodeType ) { Text textNode = Text . as ( targetNode ) ; textNode . deleteData ( position , 1 ) ; } } else if ( operation instanceof TreeInsertParagraph ) { TreeInsertParagraph treeInsertParagraph = ( ( TreeInsertParagraph ) ( operation ) ) ; final Element p = Document . get ( ) . createElement ( "p" ) ; if ( ( nativeNode . getChildCount ( ) ) == 0 ) { targetNode . insertFirst ( p ) ; } else if ( ( ( nativeNode . getChildCount ( ) ) == 1 ) && ( nativeNode . getFirstChild ( ) . getNodeName ( ) . equalsIgnoreCase ( "br" ) ) ) { log . info ( "3" ) ; nativeNode . replaceChild ( nativeNode . getFirstChild ( ) , p ) ; } else if ( position == 0 ) { p . appendChild ( Document . get ( ) . createBRElement ( ) ) ; Node parentNode = targetNode . getParentElement ( ) ; if ( ( ( path . length ) == 1 ) && ( ( path [ 0 ] ) == 0 ) ) { parentNode . insertBefore ( p , targetNode ) ; } else { parentNode . getParentNode ( ) . insertBefore ( p , parentNode ) ; } } else { log . info ( "5" ) ; String actualText = targetNode . getNodeValue ( ) ; Text textNode = Text . as ( targetNode ) ; textNode . deleteData ( 0 , position ) ; p . setInnerText ( actualText . substring ( 0 , position ) ) ; Node parentElement = targetNode . getParentElement ( ) ; parentElement . getParentElement ( ) . insertBefore ( p , parentElement ) ; } } else if ( operation instanceof TreeNewParagraph ) { TreeNewParagraph treeNewParagraph = ( ( TreeNewParagraph ) ( operation ) ) ; final Element p = Document . get ( ) . createElement ( "p" ) ; p . appendChild ( Document . get ( ) . createBRElement ( ) ) ; Node parentNode = targetNode . getParentElement ( ) ; if ( ( ( path . length ) == 1 ) && ( ( path [ 0 ] ) == 0 ) ) { parentNode . insertBefore ( p , targetNode ) ; } else { parentNode . getParentNode ( ) . insertBefore ( p , parentNode ) ; } } else if ( operation instanceof TreeMergeParagraph ) { Node p = targetNode . getParentElement ( ) ; Node pPreviousSibling = p . getPreviousSibling ( ) ; targetNode . removeFromParent ( ) ; p . removeFromParent ( ) ; <START_BUG> Node oldTextNode = pPreviousSibling . getChild ( 0 ) ; <END_BUG> Text newTextNode = Document . get ( ) . createTextNode ( ( ( oldTextNode . getNodeValue ( ) ) + ( targetNode . getNodeValue ( ) ) ) ) ; pPreviousSibling . replaceChild ( newTextNode , oldTextNode ) ; } else if ( operation instanceof TreeStyle ) { TreeStyle style = ( ( TreeStyle ) ( operation ) ) ; Node parentElement = targetNode . getParentElement ( ) ; Element styleElement = DOM . createElement ( style . param ) ; styleElement . appendChild ( targetNode ) ; parentElement . replaceChild ( styleElement , targetNode ) ; } log . fine ( ( "Native<seq2seq4repair_space>node<seq2seq4repair_space>is<seq2seq4repair_space>after:<seq2seq4repair_space>" + ( Element . as ( nativeNode ) . getString ( ) ) ) ) ; } private void handleNewParagraph ( Node targetNode , int position ) { } private void insertBrInEmptyParagraphs ( Node node ) { } No newline ; at end ; of file ; }

Fix:
Node oldTextNode = pPreviousSibling . getLastChild ( ) ;