Program: 178469
Project: 178469
Buggy source:
@Override public void onKeyDown(KeyDownEvent event){
  final int keyCode=event.getNativeKeyCode();
  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=treeOperationFactory.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(treeOperationFactory.toIntArray(path));
            }
 else {
              log.info("String_Node_Str");
            }
          }
 else {
            log.info("String_Node_Str");
            pos=pos - 1;
            op=new TreeDeleteText(clientJupiter.getSiteId(),pos,treeOperationFactory.toIntArray(path));
          }
        }
 else         if (Node.ELEMENT_NODE == startContainer.getNodeType()) {
          if (pos == 0) {
            if (startContainer.getPreviousSibling() != null) {
              log.severe("String_Node_Str");
            }
 else {
              event.preventDefault();
            }
          }
        }
      }
    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(treeOperationFactory.toIntArray(path));
        }
      }
 else {
        op=new TreeDeleteText(clientJupiter.getSiteId(),pos,treeOperationFactory.toIntArray(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(treeOperationFactory.toIntArray(path));
      }
    }
  }
break;
case KeyCodes.KEY_ENTER:
{
path=treeOperationFactory.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(treeOperationFactory.toIntArray(path));
  }
 else {
    op=new TreeInsertParagraph(clientJupiter.getSiteId(),pos,treeOperationFactory.toIntArray(path));
  }
}
 else if (Node.ELEMENT_NODE == endContainer.getNodeType()) {
  Element element=Element.as(endContainer);
  if (element.getPreviousSibling() == null && 0 == pos) {
    op=new TreeNewParagraph(clientJupiter.getSiteId(),path.get(0));
    op.setPath(treeOperationFactory.toIntArray(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(treeOperationFactory.toIntArray(path));
    }
 else {
      pos=range.getEndOffset();
      op=new TreeInsertParagraph(clientJupiter.getSiteId(),pos,treeOperationFactory.toIntArray(path));
    }
  }
}
}
break;
default :
break;
}
if (op != null) {
if (!(op instanceof TreeInsertText || op instanceof TreeDeleteText)) {
event.preventDefault();
}
clientJupiter.generate(op);
}
}
}

Fixed version (ground truth):
@Override public void onKeyDown(KeyDownEvent event){
  final int keyCode=event.getNativeKeyCode();
  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=treeOperationFactory.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(treeOperationFactory.toIntArray(path));
            }
 else {
              log.info("String_Node_Str");
            }
          }
 else {
            log.info("String_Node_Str");
            pos=pos - 1;
            op=new TreeDeleteText(clientJupiter.getSiteId(),pos,treeOperationFactory.toIntArray(path));
          }
        }
 else         if (Node.ELEMENT_NODE == startContainer.getNodeType()) {
          if (pos == 0) {
            if (startContainer.getPreviousSibling() != null) {
              log.severe("String_Node_Str");
            }
 else {
              event.preventDefault();
            }
          }
        }
      }
    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(treeOperationFactory.toIntArray(path));
        }
      }
 else {
        op=new TreeDeleteText(clientJupiter.getSiteId(),pos,treeOperationFactory.toIntArray(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(treeOperationFactory.toIntArray(path));
      }
    }
  }
break;
case KeyCodes.KEY_ENTER:
{
path=treeOperationFactory.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);
  }
  Node n=textNode;
  while (!"String_Node_Str".equalsIgnoreCase(n.getParentNode().getNodeName())) {
    n=n.getParentNode();
  }
  if ((n.getNextSibling() == null || BR.equalsIgnoreCase(n.getNextSibling().getNodeName())) && textNode.getLength() == pos) {
    isNewParagraph=true;
    pos=path.get(0) + 1;
  }
  if (isNewParagraph) {
    op=new TreeNewParagraph(clientJupiter.getSiteId(),pos);
    op.setPath(treeOperationFactory.toIntArray(path));
  }
 else {
    op=new TreeInsertParagraph(clientJupiter.getSiteId(),pos,treeOperationFactory.toIntArray(path));
  }
}
 else if (Node.ELEMENT_NODE == endContainer.getNodeType()) {
  Element element=Element.as(endContainer);
  if (element.getPreviousSibling() == null && 0 == pos) {
    op=new TreeNewParagraph(clientJupiter.getSiteId(),path.get(0));
    op.setPath(treeOperationFactory.toIntArray(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(treeOperationFactory.toIntArray(path));
    }
 else {
      pos=range.getEndOffset();
      op=new TreeInsertParagraph(clientJupiter.getSiteId(),pos,treeOperationFactory.toIntArray(path));
    }
  }
}
}
break;
default :
break;
}
if (op != null) {
if (!(op instanceof TreeInsertText || op instanceof TreeDeleteText)) {
event.preventDefault();
}
clientJupiter.generate(op);
}
}
}