Program: 178483
Project: 178483
Buggy source:
@Override public void onKeyDown(KeyDownEvent event){
  final int keyCode=event.getNativeKeyCode();
  log.fine("String_Node_Str" + keyCode + "String_Node_Str"+ event.getNativeEvent().getKeyCode());
  Selection selection=getTextArea().getDocument().getSelection();
  if (selection.getRangeCount() > 0) {
    Range range=selection.getRangeAt(0);
    logRange(range);
    int pos=-1;
    Node startContainer=range.getStartContainer();
    Node endContainer=range.getEndContainer();
    List<Integer> path=getLocator(range.getStartContainer());
    TreeOperation op=null;
switch (keyCode) {
case KeyCodes.KEY_BACKSPACE:
{
        pos=range.getStartOffset();
        log.info("String_Node_Str" + pos);
        if (Node.TEXT_NODE == startContainer.getNodeType()) {
          Text textNode=Text.as(startContainer);
          if (pos == 0) {
            log.info("String_Node_Str");
            if (textNode.getParentElement().getPreviousSibling() != null) {
              log.info("String_Node_Str");
              op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),1,1);
              op.setPath(convertPath(path));
            }
 else {
              log.info("String_Node_Str");
            }
          }
 else {
            log.info("String_Node_Str");
            pos=pos - 1;
            op=new TreeDeleteText(clientJupiter.getSiteId(),pos,convertPath(path));
          }
        }
 else         if (Node.ELEMENT_NODE == startContainer.getNodeType()) {
          if (pos == 0) {
            if (startContainer.getPreviousSibling() != null) {
            }
 else {
            }
          }
        }
      }
    break;
case KeyCodes.KEY_DELETE:
{
    if (Node.TEXT_NODE == startContainer.getNodeType()) {
      Text textNode=Text.as(startContainer);
      pos=range.getStartOffset();
      if (textNode.getLength() == pos) {
        Element sibling=textNode.getParentElement().getNextSiblingElement();
        if ((sibling != null) && (!sibling.getClassName().toLowerCase().contains("String_Node_Str"))) {
          path.set(0,path.get(0) + 1);
          op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),1,1);
          op.setPath(convertPath(path));
        }
      }
 else {
        op=new TreeDeleteText(clientJupiter.getSiteId(),pos,convertPath(path));
      }
    }
 else     if (Node.ELEMENT_NODE == startContainer.getNodeType()) {
      if (startContainer.getNextSibling() != null) {
        path.set(0,path.get(0) + 1);
        op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),1,1);
        op.setPath(convertPath(path));
      }
    }
  }
break;
case KeyCodes.KEY_ENTER:
{
path=getLocator(range.getEndContainer());
pos=range.getEndOffset();
if (Node.TEXT_NODE == endContainer.getNodeType()) {
  Text textNode=Text.as(endContainer);
  boolean isNewParagraph=false;
  if (textNode.getPreviousSibling() == null && 0 == pos) {
    isNewParagraph=true;
    pos=path.get(0);
  }
  if ((textNode.getNextSibling() == null || BR.equalsIgnoreCase(textNode.getNextSibling().getNodeName())) && textNode.getLength() == pos) {
    isNewParagraph=true;
    pos=path.get(0) + 1;
  }
  if (isNewParagraph) {
    op=new TreeNewParagraph(clientJupiter.getSiteId(),pos);
    op.setPath(convertPath(path));
  }
 else {
    op=new TreeInsertParagraph(clientJupiter.getSiteId(),pos,convertPath(path));
  }
}
 else if (Node.ELEMENT_NODE == endContainer.getNodeType()) {
  Element element=Element.as(endContainer);
  int brCount=element.getElementsByTagName(BR).getLength();
  int childCount=element.getChildCount();
  boolean isBeforeLastBrTag=((pos == (childCount - brCount)) && (BR.equalsIgnoreCase(element.getLastChild().getNodeName())));
  boolean isAfterLastTag=(pos == childCount);
  if (isBeforeLastBrTag || isAfterLastTag) {
    pos=path.get(0) + 1;
    op=new TreeNewParagraph(clientJupiter.getSiteId(),pos);
    op.setPath(convertPath(path));
  }
 else {
    pos=range.getEndOffset();
    op=new TreeInsertParagraph(clientJupiter.getSiteId(),pos,convertPath(path));
  }
}
}
break;
default :
break;
}
if (op != null) {
clientJupiter.generate(op);
}
}
}

Fixed version (ground truth):
@Override public void onKeyDown(KeyDownEvent event){
  final int keyCode=event.getNativeKeyCode();
  log.fine("String_Node_Str" + keyCode + "String_Node_Str"+ event.getNativeEvent().getKeyCode());
  Selection selection=getTextArea().getDocument().getSelection();
  if (selection.getRangeCount() > 0) {
    Range range=selection.getRangeAt(0);
    logRange(range);
    int pos=-1;
    Node startContainer=range.getStartContainer();
    Node endContainer=range.getEndContainer();
    List<Integer> path=getLocator(range.getStartContainer());
    TreeOperation op=null;
switch (keyCode) {
case KeyCodes.KEY_BACKSPACE:
{
        pos=range.getStartOffset();
        log.info("String_Node_Str" + pos);
        if (Node.TEXT_NODE == startContainer.getNodeType()) {
          Text textNode=Text.as(startContainer);
          if (pos == 0) {
            log.info("String_Node_Str");
            if (textNode.getParentElement().getPreviousSibling() != null) {
              log.info("String_Node_Str");
              op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),1,1);
              op.setPath(convertPath(path));
            }
 else {
              log.info("String_Node_Str");
            }
          }
 else {
            log.info("String_Node_Str");
            pos=pos - 1;
            op=new TreeDeleteText(clientJupiter.getSiteId(),pos,convertPath(path));
          }
        }
 else         if (Node.ELEMENT_NODE == startContainer.getNodeType()) {
          if (pos == 0) {
            if (startContainer.getPreviousSibling() != null) {
            }
 else {
            }
          }
        }
      }
    break;
case KeyCodes.KEY_DELETE:
{
    if (Node.TEXT_NODE == startContainer.getNodeType()) {
      Text textNode=Text.as(startContainer);
      pos=range.getStartOffset();
      if (textNode.getLength() == pos) {
        Element sibling=textNode.getParentElement().getNextSiblingElement();
        if ((sibling != null) && (!sibling.getClassName().toLowerCase().contains("String_Node_Str"))) {
          path.set(0,path.get(0) + 1);
          op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),1,1);
          op.setPath(convertPath(path));
        }
      }
 else {
        op=new TreeDeleteText(clientJupiter.getSiteId(),pos,convertPath(path));
      }
    }
 else     if (Node.ELEMENT_NODE == startContainer.getNodeType()) {
      if (startContainer.getNextSibling() != null) {
        path.set(0,path.get(0) + 1);
        op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),1,1);
        op.setPath(convertPath(path));
      }
    }
  }
break;
case KeyCodes.KEY_ENTER:
{
path=getLocator(range.getEndContainer());
pos=range.getEndOffset();
if (Node.TEXT_NODE == endContainer.getNodeType()) {
  Text textNode=Text.as(endContainer);
  boolean isNewParagraph=false;
  if (textNode.getPreviousSibling() == null && 0 == pos) {
    isNewParagraph=true;
    pos=path.get(0);
  }
  if ((textNode.getNextSibling() == null || BR.equalsIgnoreCase(textNode.getNextSibling().getNodeName())) && textNode.getLength() == pos) {
    isNewParagraph=true;
    pos=path.get(0) + 1;
  }
  if (isNewParagraph) {
    op=new TreeNewParagraph(clientJupiter.getSiteId(),pos);
    op.setPath(convertPath(path));
  }
 else {
    op=new TreeInsertParagraph(clientJupiter.getSiteId(),pos,convertPath(path));
  }
}
 else if (Node.ELEMENT_NODE == endContainer.getNodeType()) {
  Element element=Element.as(endContainer);
  if (pos == 0) {
    op=new TreeNewParagraph(clientJupiter.getSiteId(),path.get(0));
    op.setPath(convertPath(path));
  }
 else {
    int brCount=element.getElementsByTagName(BR).getLength();
    int childCount=element.getChildCount();
    boolean isBeforeLastBrTag=((pos == (childCount - brCount)) && (BR.equalsIgnoreCase(element.getLastChild().getNodeName())));
    boolean isAfterLastTag=(pos == childCount);
    if (isBeforeLastBrTag || isAfterLastTag) {
      pos=path.get(0) + 1;
      op=new TreeNewParagraph(clientJupiter.getSiteId(),pos);
      op.setPath(convertPath(path));
    }
 else {
      pos=range.getEndOffset();
      op=new TreeInsertParagraph(clientJupiter.getSiteId(),pos,convertPath(path));
    }
  }
}
}
break;
default :
break;
}
if (op != null) {
clientJupiter.generate(op);
}
}
}