nus-yam/ex-repair huggingface dataset:
Program: 178454
Project: 178454
Buggy source:
public TreeOperation handleBackspaceOnElement(Range caret){
  int pos=caret.getStartOffset();
  Node startContainer=caret.getStartContainer();
  List<Integer> path=TreeHelper.getLocator(startContainer);
  TreeOperation op=null;
  Element rightParagraph;
  Node n;
  Node leftParagraph;
  Element element=Element.as(startContainer);
  boolean merge=false;
  if (P.equalsIgnoreCase(element.getNodeName())) {
    rightParagraph=element;
    merge=true;
  }
 else {
    log.severe("String_Node_Str");
    n=getAncestorBelowParagraph(startContainer);
    rightParagraph=n.getParentElement();
    if (pos == 0 && SPAN.equalsIgnoreCase(element.getNodeName())) {
      merge=(element == n && n == rightParagraph.getFirstChild());
    }
  }
  leftParagraph=rightParagraph.getPreviousSibling();
  merge=merge && (leftParagraph != null);
  if (merge) {
    int brCount=rightParagraph.getElementsByTagName(BR).getLength();
    op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),leftParagraph.getChildCount(),rightParagraph.getChildCount() - brCount);
    op.setPath(TreeHelper.toIntArray(path));
  }
 else {
    log.fine("String_Node_Str" + element.getTagName() + "String_Node_Str");
  }
  return op;
}

Fixed version (ground truth):
public TreeOperation handleBackspaceOnElement(Range caret){
  int pos=caret.getStartOffset();
  Node startContainer=caret.getStartContainer();
  List<Integer> path=TreeHelper.getLocator(startContainer);
  TreeOperation op=null;
  Element rightParagraph;
  Node n;
  Node leftParagraph;
  Element element=Element.as(startContainer);
  boolean merge=false;
  if (P.equalsIgnoreCase(element.getNodeName())) {
    rightParagraph=element;
    merge=true;
  }
 else {
    log.severe("String_Node_Str");
    n=getAncestorBelowParagraph(startContainer);
    rightParagraph=n.getParentElement();
    if (pos == 0 && SPAN.equalsIgnoreCase(element.getNodeName())) {
      merge=(element == n && n == rightParagraph.getFirstChild());
    }
  }
  leftParagraph=rightParagraph.getPreviousSibling();
  merge=merge && (leftParagraph != null);
  if (merge) {
    int lBrCount=Element.as(leftParagraph).getElementsByTagName(BR).getLength();
    int rBrCount=rightParagraph.getElementsByTagName(BR).getLength();
    op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),leftParagraph.getChildCount() - lBrCount,rightParagraph.getChildCount() - rBrCount);
    op.setPath(TreeHelper.toIntArray(path));
  }
 else {
    log.fine("String_Node_Str" + element.getTagName() + "String_Node_Str");
  }
  return op;
}
Program: 178455
Project: 178455
Buggy source:
private TreeOperation handleBackspaceOrDeleteKeyOnEmptyTexts(boolean isBackspace,Node node,Node rightParagraph,Node leftParagraph){
  org.xwiki.gwt.dom.client.Document document=getTextArea().getDocument();
  Range range=document.createRange();
  if (isBackspace) {
    range.setStartAfter(document.getBody().getFirstChild());
    range.setEndBefore(node);
  }
 else {
    range.setStartAfter(node);
    range.setEndBefore(document.getBody().getLastChild());
  }
  TreeOperation op=null;
  List<Text> nonEmptyTextNodes=getNonEmptyTextNodes(range);
  if (nonEmptyTextNodes.size() > 0) {
    int idx=isBackspace ? nonEmptyTextNodes.size() - 1 : 0;
    Node prevNonEmptyTextNode=nonEmptyTextNodes.get(idx);
    log.fine("String_Node_Str" + prevNonEmptyTextNode.getNodeValue());
    List<Integer> path;
    if (node.getParentNode() == prevNonEmptyTextNode.getParentNode()) {
      int deletePos=isBackspace ? prevNonEmptyTextNode.getNodeValue().length() - 1 : 0;
      path=TreeHelper.getLocator(prevNonEmptyTextNode);
      op=new TreeDeleteText(clientJupiter.getSiteId(),deletePos,TreeHelper.toIntArray(path));
    }
 else {
      int brCount=Element.as(rightParagraph).getElementsByTagName(BR).getLength();
      path=TreeHelper.getLocator(prevNonEmptyTextNode);
      op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),leftParagraph.getChildCount(),rightParagraph.getChildCount() - brCount);
      op.setPath(TreeHelper.toIntArray(path));
    }
  }
  return op;
}

Fixed version (ground truth):
private TreeOperation handleBackspaceOrDeleteKeyOnEmptyTexts(boolean isBackspace,Node node,Node rightParagraph,Node leftParagraph){
  org.xwiki.gwt.dom.client.Document document=getTextArea().getDocument();
  Range range=document.createRange();
  if (isBackspace) {
    range.setStartAfter(document.getBody().getFirstChild());
    range.setEndBefore(node);
  }
 else {
    range.setStartAfter(node);
    range.setEndBefore(document.getBody().getLastChild());
  }
  TreeOperation op=null;
  List<Text> nonEmptyTextNodes=getNonEmptyTextNodes(range);
  if (nonEmptyTextNodes.size() > 0) {
    int idx=isBackspace ? nonEmptyTextNodes.size() - 1 : 0;
    Node prevNonEmptyTextNode=nonEmptyTextNodes.get(idx);
    log.fine("String_Node_Str" + prevNonEmptyTextNode.getNodeValue());
    List<Integer> path;
    if (node.getParentNode() == prevNonEmptyTextNode.getParentNode()) {
      int deletePos=isBackspace ? prevNonEmptyTextNode.getNodeValue().length() - 1 : 0;
      path=TreeHelper.getLocator(prevNonEmptyTextNode);
      op=new TreeDeleteText(clientJupiter.getSiteId(),deletePos,TreeHelper.toIntArray(path));
    }
 else {
      int lBbrCount=Element.as(leftParagraph).getElementsByTagName(BR).getLength();
      int rBbrCount=Element.as(rightParagraph).getElementsByTagName(BR).getLength();
      path=TreeHelper.getLocator(prevNonEmptyTextNode);
      op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),leftParagraph.getChildCount() - lBbrCount,rightParagraph.getChildCount() - rBbrCount);
      op.setPath(TreeHelper.toIntArray(path));
    }
  }
  return op;
}
Program: 178456
Project: 178456
Buggy source:
public TreeOperation handleBackspaceOnTextNode(Range caret){
  int pos=caret.getStartOffset();
  Node startContainer=caret.getStartContainer();
  List<Integer> path=TreeHelper.getLocator(startContainer);
  TreeOperation op=null;
  Node ancestorBelowParagraph=getAncestorBelowParagraph(startContainer);
  Element rightParagraph=ancestorBelowParagraph.getParentElement();
  Node leftParagraph=rightParagraph.getPreviousSibling();
  Text textNode=Text.as(startContainer);
  if (pos == 0) {
    if (leftParagraph != null) {
      boolean merge=false;
      if (textNode != ancestorBelowParagraph && textNode == ancestorBelowParagraph.getFirstChild()) {
        merge=true;
      }
      if (textNode == ancestorBelowParagraph && ancestorBelowParagraph == rightParagraph.getFirstChild()) {
        merge=true;
      }
      if (merge) {
        int brCount=rightParagraph.getElementsByTagName(BR).getLength();
        op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),leftParagraph.getChildCount(),rightParagraph.getChildCount() - brCount);
        op.setPath(TreeHelper.toIntArray(path));
      }
 else {
        op=skipBackspaceOnEmptyTexts(textNode,rightParagraph,leftParagraph);
      }
    }
 else {
      log.fine("String_Node_Str");
    }
  }
 else {
    pos=pos - 1;
    op=new TreeDeleteText(clientJupiter.getSiteId(),pos,TreeHelper.toIntArray(path));
  }
  return op;
}

Fixed version (ground truth):
public TreeOperation handleBackspaceOnTextNode(Range caret){
  int pos=caret.getStartOffset();
  Node startContainer=caret.getStartContainer();
  List<Integer> path=TreeHelper.getLocator(startContainer);
  TreeOperation op=null;
  Node ancestorBelowParagraph=getAncestorBelowParagraph(startContainer);
  Element rightParagraph=ancestorBelowParagraph.getParentElement();
  Node leftParagraph=rightParagraph.getPreviousSibling();
  Text textNode=Text.as(startContainer);
  if (pos == 0) {
    if (leftParagraph != null) {
      boolean merge=false;
      if (textNode != ancestorBelowParagraph && textNode == ancestorBelowParagraph.getFirstChild()) {
        merge=true;
      }
      if (textNode == ancestorBelowParagraph && ancestorBelowParagraph == rightParagraph.getFirstChild()) {
        merge=true;
      }
      if (merge) {
        int lBrCount=Element.as(leftParagraph).getElementsByTagName(BR).getLength();
        int rBrCount=rightParagraph.getElementsByTagName(BR).getLength();
        op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0),leftParagraph.getChildCount() - lBrCount,rightParagraph.getChildCount() - rBrCount);
        op.setPath(TreeHelper.toIntArray(path));
      }
 else {
        op=skipBackspaceOnEmptyTexts(textNode,rightParagraph,leftParagraph);
      }
    }
 else {
      log.fine("String_Node_Str");
    }
  }
 else {
    pos=pos - 1;
    op=new TreeDeleteText(clientJupiter.getSiteId(),pos,TreeHelper.toIntArray(path));
  }
  return op;
}
Program: 178457
Project: 178457
Buggy source:
public TreeOperation handleDeleteOnElement(Range caret){
  Element element=Element.as(caret.getStartContainer());
  List<Integer> path=TreeHelper.getLocator(element);
  TreeOperation op=null;
  Element leftParagraph;
  Element rightParagraph;
  if (P.equalsIgnoreCase(element.getNodeName())) {
    leftParagraph=element;
  }
 else {
    log.severe("String_Node_Str");
    leftParagraph=getAncestorBelowParagraph(element).getParentElement();
  }
  rightParagraph=leftParagraph.getNextSiblingElement();
  if (rightParagraph != null) {
    int brCount=rightParagraph.getElementsByTagName(BR).getLength();
    op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0) + 1,leftParagraph.getChildCount(),rightParagraph.getChildCount() - brCount);
    op.setPath(TreeHelper.toIntArray(path));
  }
 else {
    log.fine("String_Node_Str");
  }
  return op;
}

Fixed version (ground truth):
public TreeOperation handleDeleteOnElement(Range caret){
  Element element=Element.as(caret.getStartContainer());
  List<Integer> path=TreeHelper.getLocator(element);
  TreeOperation op=null;
  Element leftParagraph;
  Element rightParagraph;
  if (P.equalsIgnoreCase(element.getNodeName())) {
    leftParagraph=element;
  }
 else {
    log.severe("String_Node_Str");
    leftParagraph=getAncestorBelowParagraph(element).getParentElement();
  }
  rightParagraph=leftParagraph.getNextSiblingElement();
  if (rightParagraph != null) {
    int lBrCount=leftParagraph.getElementsByTagName(BR).getLength();
    int rBrCount=rightParagraph.getElementsByTagName(BR).getLength();
    op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0) + 1,leftParagraph.getChildCount() - lBrCount,rightParagraph.getChildCount() - rBrCount);
    op.setPath(TreeHelper.toIntArray(path));
  }
 else {
    log.fine("String_Node_Str");
  }
  return op;
}
Program: 178458
Project: 178458
Buggy source:
public TreeOperation handleDeleteOnTextNode(Range caret){
  int pos=caret.getStartOffset();
  Node startContainer=caret.getStartContainer();
  Text textNode=Text.as(startContainer);
  List<Integer> path=TreeHelper.getLocator(startContainer);
  TreeOperation op=null;
  Element leftParagraph;
  Element rightParagraph;
  final Node ancestorBelowParagraph=getAncestorBelowParagraph(startContainer);
  leftParagraph=ancestorBelowParagraph.getParentElement();
  rightParagraph=leftParagraph.getNextSiblingElement();
  boolean isMerge=false;
  if (textNode != ancestorBelowParagraph) {
    isMerge=ancestorBelowParagraph == ancestorBelowParagraph.getParentNode().getLastChild();
    isMerge=isMerge && textNode == ancestorBelowParagraph.getLastChild();
  }
 else {
    isMerge=textNode == ancestorBelowParagraph.getParentElement().getLastChild();
  }
  isMerge=isMerge && ((rightParagraph != null) && (!rightParagraph.getClassName().toLowerCase().contains("String_Node_Str")));
  if (textNode.getLength() == pos) {
    if (isMerge) {
      int brCount=rightParagraph.getElementsByTagName(BR).getLength();
      op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0) + 1,leftParagraph.getChildCount(),rightParagraph.getChildCount() - brCount);
      op.setPath(TreeHelper.toIntArray(path));
    }
 else {
      log.fine("String_Node_Str");
    }
  }
 else {
    op=skipDeleteOnEmptyTexts(textNode,leftParagraph,rightParagraph);
  }
  return op;
}

Fixed version (ground truth):
public TreeOperation handleDeleteOnTextNode(Range caret){
  int pos=caret.getStartOffset();
  Node startContainer=caret.getStartContainer();
  Text textNode=Text.as(startContainer);
  List<Integer> path=TreeHelper.getLocator(startContainer);
  TreeOperation op=null;
  Element leftParagraph;
  Element rightParagraph;
  final Node ancestorBelowParagraph=getAncestorBelowParagraph(startContainer);
  leftParagraph=ancestorBelowParagraph.getParentElement();
  rightParagraph=leftParagraph.getNextSiblingElement();
  boolean isMerge=false;
  if (textNode != ancestorBelowParagraph) {
    isMerge=ancestorBelowParagraph == ancestorBelowParagraph.getParentNode().getLastChild();
    isMerge=isMerge && textNode == ancestorBelowParagraph.getLastChild();
  }
 else {
    isMerge=textNode == ancestorBelowParagraph.getParentElement().getLastChild();
  }
  isMerge=isMerge && ((rightParagraph != null) && (!rightParagraph.getClassName().toLowerCase().contains("String_Node_Str")));
  if (textNode.getLength() == pos) {
    if (isMerge) {
      int lBrCount=leftParagraph.getElementsByTagName(BR).getLength();
      int rBrCount=rightParagraph.getElementsByTagName(BR).getLength();
      op=new TreeMergeParagraph(clientJupiter.getSiteId(),path.get(0) + 1,leftParagraph.getChildCount() - lBrCount,rightParagraph.getChildCount() - rBrCount);
      op.setPath(TreeHelper.toIntArray(path));
    }
 else {
      log.fine("String_Node_Str");
    }
  }
 else {
    op=skipDeleteOnEmptyTexts(textNode,leftParagraph,rightParagraph);
  }
  return op;
}
Program: 178460
Project: 178460
Buggy source:
/** 
 * @param range the selection range, usually a collapsed range which is the caret position
 * @return all the non-empty text nodes from the right of the caret within the same paragraph
 */
private static List<Text> getRightTextNodesInSameP(Range range){
  Range rightRange=range.cloneRange();
  Node parentPNode=getAncestorParagraph(range.getEndContainer());
  rightRange.setEndAfter(parentPNode.getLastChild());
  return getNonEmptyTextNodes(rightRange);
}

Fixed version (ground truth):
/** 
 * @param range the selection range, usually a collapsed range which is the caret position
 * @return all the non-empty text nodes from the right of the caret within the same paragraph
 */
private static List<Text> getRightTextNodesInSameP(Range range){
  Range rightRange=range.cloneRange();
  Node parentPNode=getAncestorParagraph(range.getEndContainer());
  rightRange.setEnd(parentPNode,parentPNode.getChildCount());
  return getNonEmptyTextNodes(rightRange);
}
Program: 178461
Project: 178461
Buggy source:
/** 
 * @param oldCaretPosition the old caret position
 * @return the new caret position, as described above
 */
public static Range computeNewCaretPosition(Range oldCaretPosition){
  Range newCaretPos=null;
  if (oldCaretPosition.isCollapsed()) {
    newCaretPos=oldCaretPosition.cloneRange();
    if (isNonEmptyTextNode(oldCaretPosition.getStartContainer())) {
      return oldCaretPosition;
    }
 else {
      List<Text> leftTextNodesInSameP=getLeftTextNodesInSameP(oldCaretPosition);
      int leftSize=leftTextNodesInSameP.size();
      if (leftSize > 0) {
        Text firstLeftTextNode=leftTextNodesInSameP.get(leftSize - 1);
        newCaretPos.setStart(firstLeftTextNode,firstLeftTextNode.getLength());
      }
 else {
        List<Text> rightTextNodesInSameP=getRightTextNodesInSameP(oldCaretPosition);
        if (rightTextNodesInSameP.size() > 0) {
          Text firstRightTextNode=rightTextNodesInSameP.get(0);
          newCaretPos.setStart(firstRightTextNode,0);
        }
      }
    }
    newCaretPos.collapse(true);
  }
  return newCaretPos;
}

Fixed version (ground truth):
/** 
 * @param oldCaretPosition the old caret position
 * @return the new caret position, as described above
 */
public static Range computeNewCaretPosition(Range oldCaretPosition){
  Range newCaretPos=null;
  if (oldCaretPosition.isCollapsed()) {
    newCaretPos=oldCaretPosition.cloneRange();
    if (isNonEmptyTextNode(oldCaretPosition.getStartContainer()) && oldCaretPosition.getStartOffset() > 0) {
      return oldCaretPosition;
    }
 else {
      List<Text> leftTextNodesInSameP=getLeftTextNodesInSameP(oldCaretPosition);
      int leftSize=leftTextNodesInSameP.size();
      if (leftSize > 0) {
        Text firstLeftTextNode=leftTextNodesInSameP.get(leftSize - 1);
        newCaretPos.setStart(firstLeftTextNode,firstLeftTextNode.getLength());
      }
 else {
        List<Text> rightTextNodesInSameP=getRightTextNodesInSameP(oldCaretPosition);
        if (rightTextNodesInSameP.size() > 0) {
          Text firstRightTextNode=rightTextNodesInSameP.get(0);
          newCaretPos.setStart(firstRightTextNode,0);
        }
      }
    }
    newCaretPos.collapse(true);
  }
  return newCaretPos;
}
Program: 178462
Project: 178462
Buggy source:
public void testCaretInChildElementStartOfTextNode(){
  Element element=getContainer().getFirstChildElement();
  assertNotNull(element);
  assertEquals("String_Node_Str","String_Node_Str",element.getNodeName().toLowerCase());
  assertEquals(Node.TEXT_NODE,element.getFirstChild().getNodeType());
  Text textNode=Text.as(element.getFirstChild());
  oldCaretPos.setStart(textNode,0);
  oldCaretPos.setEnd(textNode,0);
  Range newCaretPos=EditorUtils.computeNewCaretPosition(oldCaretPos);
  assertEquals(Node.TEXT_NODE,newCaretPos.getStartContainer().getNodeType());
  assertEquals(textNode,newCaretPos.getStartContainer());
  assertEquals(0,newCaretPos.getStartOffset());
  assertTrue(newCaretPos.isCollapsed());
}

Fixed version (ground truth):
public void testCaretInChildElementStartOfTextNode(){
  Element element=getContainer().getFirstChildElement();
  assertNotNull(element);
  assertEquals("String_Node_Str","String_Node_Str",element.getNodeName().toLowerCase());
  assertEquals(Node.TEXT_NODE,element.getFirstChild().getNodeType());
  Text textNode=Text.as(element.getFirstChild());
  oldCaretPos.setStart(textNode,0);
  oldCaretPos.setEnd(textNode,0);
  Range newCaretPos=EditorUtils.computeNewCaretPosition(oldCaretPos);
  Text expectedTextNode=Text.as(getContainer().getFirstChild());
  assertEquals(Node.TEXT_NODE,expectedTextNode.getNodeType());
  assertEquals(Node.TEXT_NODE,newCaretPos.getStartContainer().getNodeType());
  assertEquals(expectedTextNode,newCaretPos.getStartContainer());
  assertEquals(expectedTextNode.getLength(),newCaretPos.getStartOffset());
  assertTrue(newCaretPos.isCollapsed());
}
Program: 178463
Project: 178463
Buggy source:
public void testCaretAfterSpanStartOfTextNode(){
  Element spanElement=getContainer().getFirstChildElement();
  assertNotNull(spanElement);
  assertEquals("String_Node_Str","String_Node_Str",spanElement.getNodeName().toLowerCase());
  Text expectedText=Text.as(spanElement.getFirstChild());
  assertEquals(Node.TEXT_NODE,expectedText.getNodeType());
  oldCaretPos.setStart(expectedText,0);
  oldCaretPos.setEnd(expectedText,0);
  Range newCaretPos=EditorUtils.computeNewCaretPosition(oldCaretPos);
  assertEquals(oldCaretPos,newCaretPos);
  assertEquals(Node.TEXT_NODE,newCaretPos.getStartContainer().getNodeType());
  assertEquals(expectedText,newCaretPos.getStartContainer());
  assertEquals(0,newCaretPos.getStartOffset());
  assertTrue(newCaretPos.isCollapsed());
}

Fixed version (ground truth):
public void testCaretAfterSpanStartOfTextNode(){
  Element spanElement=getContainer().getFirstChildElement();
  assertNotNull(spanElement);
  assertEquals("String_Node_Str","String_Node_Str",spanElement.getNodeName().toLowerCase());
  Text text=Text.as(spanElement.getNextSibling());
  assertEquals(Node.TEXT_NODE,text.getNodeType());
  oldCaretPos.setStart(text,0);
  oldCaretPos.setEnd(text,0);
  Range newCaretPos=EditorUtils.computeNewCaretPosition(oldCaretPos);
  Text expectedText=Text.as(spanElement.getFirstChild());
  assertEquals(Node.TEXT_NODE,expectedText.getNodeType());
  assertEquals(Node.TEXT_NODE,newCaretPos.getStartContainer().getNodeType());
  assertEquals(expectedText,newCaretPos.getStartContainer());
  assertEquals(expectedText.getLength(),newCaretPos.getStartOffset());
  assertTrue(newCaretPos.isCollapsed());
}
Program: 178466
Project: 178466
Buggy source:
public void removeChild(){
  for (int i=0; i < this.wrappedTree.nbChildren(); i++) {
    this.wrappedTree.removeChild(i);
  }
}

Fixed version (ground truth):
public void removeChild(){
  int childCount=this.wrappedTree.nbChildren();
  for (int i=0; i < childCount; i++) {
    this.wrappedTree.removeChild(0);
  }
}
Program: 178468
Project: 178468
Buggy source:
/** 
 * @param text the text node whose ancestor is to be returned
 * @return the ancestor for this text node which is just below the paragraph ancestor
 */
private Node getAncestorBelowParagraph(Text text){
  Node n=text;
  while (!"String_Node_Str".equalsIgnoreCase(n.getParentNode().getNodeName())) {
    n=n.getParentNode();
  }
  return n;
}

Fixed version (ground truth):
/** 
 * @param node the node whose ancestor is to be returned
 * @return the ancestor for this node which is just below the paragraph ancestor
 */
private Node getAncestorBelowParagraph(Node node){
  Node ancestor=node;
  while (!"String_Node_Str".equalsIgnoreCase(ancestor.getParentNode().getNodeName())) {
    ancestor=ancestor.getParentNode();
  }
  return ancestor;
}
Program: 178470
Project: 178470
Buggy source:
/** 
 * Adds the underlying style to the given text node.
 * @param text           the target text node
 * @param firstCharIndex the first character on which we apply the style
 * @param lastCharIndex  the last character on which we apply the style
 * @return a text fragment indicating what has been formatted
 */
protected TextFragment addStyle(Text text,int firstCharIndex,int lastCharIndex){
  if (matchesStyle(text)) {
    return new TextFragment(text,firstCharIndex,lastCharIndex);
  }
  text.crop(firstCharIndex,lastCharIndex);
  Element element=(Element)text.getParentElement();
  if (SPAN.equalsIgnoreCase(element.getNodeName())) {
    element.getStyle().setProperty(getProperty().getJSName(),propertyValue);
  }
 else {
    SpanElement spanElement=Document.get().createSpanElement();
    spanElement.getStyle().setProperty(getProperty().getJSName(),propertyValue);
    element.replaceChild(spanElement,text);
    spanElement.appendChild(text);
  }
  return new TextFragment(text,0,text.getLength());
}

Fixed version (ground truth):
/** 
 * Adds the underlying style to the given text node.
 * @param text           the target text node
 * @param firstCharIndex the first character on which we apply the style
 * @param lastCharIndex  the last character on which we apply the style
 * @return a text fragment indicating what has been formatted
 */
protected TextFragment addStyle(Text text,int firstCharIndex,int lastCharIndex){
  if (matchesStyle(text)) {
    return new TextFragment(text,firstCharIndex,lastCharIndex);
  }
  text.crop(firstCharIndex,lastCharIndex);
  Element element=(Element)text.getParentElement();
  if (SPAN.equalsIgnoreCase(element.getNodeName())) {
    if (element.getChildCount() != 1) {
      splitParentNode(text,element);
    }
    element.getStyle().setProperty(getProperty().getJSName(),propertyValue);
  }
 else {
    SpanElement spanElement=Document.get().createSpanElement();
    spanElement.getStyle().setProperty(getProperty().getJSName(),propertyValue);
    element.replaceChild(spanElement,text);
    spanElement.appendChild(text);
  }
  return new TextFragment(text,0,text.getLength());
}
Program: 178471
Project: 178471
Buggy source:
@Override public boolean isExecuted(){
  Selection selection=document.getSelection();
  for (int i=0; i < selection.getRangeCount(); i++) {
    if (!isExecuted(selection.getRangeAt(i))) {
      return false;
    }
  }
  return selection.getRangeCount() > 0;
}

Fixed version (ground truth):
@Override public boolean isExecuted(){
  return isExecuted(styleRange);
}
Program: 178472
Project: 178472
Buggy source:
/** 
 * Override because of a bug
 */
@Override protected boolean matchesInheritedStyle(Element element){
  final com.google.gwt.dom.client.Style style=element.getStyle();
  String computedValue;
  if (style != null && style.getProperty(getProperty().getJSName()).length() > 0) {
    log.fine("String_Node_Str");
    computedValue=style.getProperty(getProperty().getJSName());
  }
 else {
    log.fine("String_Node_Str");
    computedValue=element.getComputedStyleProperty(getProperty().getJSName());
  }
  log.fine("String_Node_Str" + computedValue);
  if (getProperty().isMultipleValue()) {
    return computedValue != null && computedValue.toLowerCase().contains(propertyValue);
  }
 else {
    return propertyValue.equalsIgnoreCase(computedValue);
  }
}

Fixed version (ground truth):
/** 
 * Override because of a bug
 */
@Override protected boolean matchesInheritedStyle(Element element){
  final com.google.gwt.dom.client.Style style=element.getStyle();
  String computedValue;
  if (style != null && style.getProperty(getProperty().getJSName()).length() > 0) {
    computedValue=style.getProperty(getProperty().getJSName());
  }
 else {
    computedValue=element.getComputedStyleProperty(getProperty().getJSName());
  }
  log.fine("String_Node_Str" + computedValue);
  if (getProperty().isMultipleValue()) {
    return computedValue != null && computedValue.toLowerCase().contains(propertyValue);
  }
 else {
    return propertyValue.equalsIgnoreCase(computedValue);
  }
}
Program: 178473
Project: 178473
Buggy source:
/** 
 * {@inheritDoc}
 * @see AbstractPlugin#init(RichTextArea,Config)
 */
public void init(RichTextArea textArea,Config config){
  super.init(textArea,config);
  saveRegistration(textArea.addKeyDownHandler(this));
  saveRegistration(textArea.addKeyPressHandler(this));
  saveRegistration(textArea.addKeyUpHandler(this));
  getTextArea().getCommandManager().addCommandListener(this);
  Node bodyNode=textArea.getDocument().getBody();
  final Element p=Document.get().createElement("String_Node_Str");
  if (bodyNode.getChildCount() == 0) {
    bodyNode.insertFirst(p);
  }
 else   if (bodyNode.getChildCount() == 1 && bodyNode.getFirstChild().getNodeName().equalsIgnoreCase("String_Node_Str")) {
    bodyNode.insertBefore(p,bodyNode.getFirstChild());
  }
  Tree t=Converter.fromNativeToCustom(Element.as(bodyNode));
  clientJupiter=new ClientJupiterAlg(new TreeDocument(t));
  clientJupiter.setEditingSessionId(Integer.parseInt(config.getParameter(RtApi.DOCUMENT_ID)));
  clientJupiter.setCommunicationService(CommunicationService.ServiceHelper.getCommunicationService());
  clientJupiter.setCallback(new TreeClientCallback(bodyNode));
  clientJupiter.connect();
  customizeActionListeners();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 * @see AbstractPlugin#init(RichTextArea,Config)
 */
public void init(RichTextArea textArea,Config config){
  super.init(textArea,config);
  saveRegistration(textArea.addKeyDownHandler(this));
  saveRegistration(textArea.addKeyPressHandler(this));
  saveRegistration(textArea.addKeyUpHandler(this));
  getTextArea().getCommandManager().addCommandListener(this);
  Node bodyNode=textArea.getDocument().getBody();
  final Element p=Document.get().createElement("String_Node_Str");
  if (bodyNode.getChildCount() == 0) {
    bodyNode.insertFirst(p);
  }
 else   if (bodyNode.getChildCount() == 1 && bodyNode.getFirstChild().getNodeName().equalsIgnoreCase(BR)) {
    bodyNode.insertBefore(p,bodyNode.getFirstChild());
  }
  Tree t=Converter.fromNativeToCustom(Element.as(bodyNode));
  clientJupiter=new ClientJupiterAlg(new TreeDocument(t));
  clientJupiter.setEditingSessionId(Integer.parseInt(config.getParameter(RtApi.DOCUMENT_ID)));
  clientJupiter.setCommunicationService(CommunicationService.ServiceHelper.getCommunicationService());
  clientJupiter.setCallback(new TreeClientCallback(bodyNode));
  clientJupiter.connect();
  customizeActionListeners();
}
Program: 178475
Project: 178475
Buggy source:
@Override public boolean isExecuted(){
  Selection selection=document.getSelection();
  for (int i=0; i < selection.getRangeCount(); i++) {
    if (!isExecuted(selection.getRangeAt(i))) {
      return false;
    }
  }
  return selection.getRangeCount() > 0;
}

Fixed version (ground truth):
@Override public boolean isExecuted(){
  return ((TreeStyle)DomStyle.this.getOperation()).addStyle;
}
Program: 178476
Project: 178476
Buggy source:
@Override protected Range execute(Range range,String parameter){
  return super.execute(range,parameter);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 * @see InlineStyleExecutable#execute(Text,int,int,String)
 */
protected TextFragment execute(Text text,int startIndex,int endIndex,String parameter){
  boolean wasExecuted=isExecuted();
  log.info("String_Node_Str" + wasExecuted);
  return wasExecuted ? removeStyle(text,startIndex,endIndex) : addStyle(text,startIndex,endIndex);
}
Program: 178477
Project: 178477
Buggy source:
/** 
 * Adds the underlying style to the given text node.
 * @param text           the target text node
 * @param firstCharIndex the first character on which we apply the style
 * @param lastCharIndex  the last character on which we apply the style
 * @return a text fragment indicating what has been formatted
 */
protected TextFragment addStyle(Text text,int firstCharIndex,int lastCharIndex){
  if (matchesStyle(text)) {
    return new TextFragment(text,firstCharIndex,lastCharIndex);
  }
  text.crop(firstCharIndex,lastCharIndex);
  Element element=(Element)text.getParentElement();
  if ("String_Node_Str".equalsIgnoreCase(element.getNodeName())) {
    element.getStyle().setProperty(getProperty().getJSName(),propertyValue);
  }
 else {
    text.removeFromParent();
    SpanElement spanElement=Document.get().createSpanElement();
    spanElement.setAttribute(getProperty().getJSName(),propertyValue);
    spanElement.appendChild(text);
    element.appendChild(spanElement);
  }
  return new TextFragment(text,0,text.getLength());
}

Fixed version (ground truth):
/** 
 * Adds the underlying style to the given text node.
 * @param text           the target text node
 * @param firstCharIndex the first character on which we apply the style
 * @param lastCharIndex  the last character on which we apply the style
 * @return a text fragment indicating what has been formatted
 */
protected TextFragment addStyle(Text text,int firstCharIndex,int lastCharIndex){
  if (matchesStyle(text)) {
    return new TextFragment(text,firstCharIndex,lastCharIndex);
  }
  text.crop(firstCharIndex,lastCharIndex);
  Element element=(Element)text.getParentElement();
  if (SPAN.equalsIgnoreCase(element.getNodeName())) {
    element.getStyle().setProperty(getProperty().getJSName(),propertyValue);
  }
 else {
    SpanElement spanElement=Document.get().createSpanElement();
    spanElement.getStyle().setProperty(getProperty().getJSName(),propertyValue);
    element.replaceChild(spanElement,text);
    spanElement.appendChild(text);
  }
  return new TextFragment(text,0,text.getLength());
}
Program: 178478
Project: 178478
Buggy source:
/** 
 * {@inheritDoc}
 * @see InlineStyleExecutable#execute(Text,int,int,String)
 */
protected TextFragment execute(Text text,int startIndex,int endIndex,String parameter){
  boolean wasExecuted=isExecuted();
  log.info("String_Node_Str" + wasExecuted);
  return wasExecuted ? removeStyle(text,startIndex,endIndex) : addStyle(text,startIndex,endIndex);
}

Fixed version (ground truth):
@Override protected TextFragment execute(Text text,int startIndex,int endIndex,String parameter){
  boolean addStyle=isExecuted();
  return addStyle ? addStyle(text,startIndex,endIndex) : removeStyle(text,startIndex,endIndex);
}
Program: 178479
Project: 178479
Buggy source:
public TreeStyle(int siteId,int[] path,int start,int end,String param,String value,boolean addStyle,boolean splitLeft,boolean splitRight){
  this.path=path;
  this.start=start;
  this.end=end;
  this.param=param;
  this.value=value;
  this.siteId=siteId;
  this.addStyle=addStyle;
  this.splitLeft=splitLeft;
  this.splitRight=splitRight;
}

Fixed version (ground truth):
public TreeStyle(int siteId,int[] path,int start,int end,String param,String value,boolean addStyle,boolean splitLeft,boolean splitRight){
  this.path=path;
  this.start=Math.min(start,end);
  this.end=Math.max(start,end);
  this.param=param;
  this.value=value;
  this.siteId=siteId;
  this.addStyle=addStyle;
  this.splitLeft=splitLeft;
  this.splitRight=splitRight;
}
Program: 178484
Project: 178484
Buggy source:
/** 
 * {@inheritDoc}
 * @see KeyPressHandler#onKeyPress(KeyPressEvent)
 */
public void onKeyPress(KeyPressEvent event){
  log.info("String_Node_Str" + getTextArea().getHTML());
  boolean isAltControlOrMetaDown=event.isAltKeyDown() || event.isControlKeyDown() || event.isMetaKeyDown();
  boolean isNoteworthyKeyPressed=event.getCharCode() != '\u0000';
  if (getTextArea().isAttached() && getTextArea().isEnabled() && !isAltControlOrMetaDown&& isNoteworthyKeyPressed) {
    Selection selection=getTextArea().getDocument().getSelection();
    if (selection.getRangeCount() > 0) {
      Range range=selection.getRangeAt(0);
      logRange(range);
      List<Integer> path=getLocator(range.getStartContainer());
      clientJupiter.generate(new TreeInsertText(clientJupiter.getSiteId(),range.getStartOffset(),convertPath(path),new String(new int[]{event.getUnicodeCharCode()},0,1).charAt(0)));
    }
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 * @see KeyPressHandler#onKeyPress(KeyPressEvent)
 */
public void onKeyPress(KeyPressEvent event){
  log.info("String_Node_Str" + getTextArea().getHTML());
  log.fine("String_Node_Str" + event.getCharCode() + "String_Node_Str"+ event.getNativeEvent().getKeyCode()+ "String_Node_Str"+ event.getUnicodeCharCode());
  boolean isAltControlOrMetaDown=event.isAltKeyDown() || event.isControlKeyDown() || event.isMetaKeyDown();
  boolean isNoteworthyKeyPressed=event.getCharCode() != '\u0000';
  log.info("String_Node_Str" + isNoteworthyKeyPressed);
  if (getTextArea().isAttached() && getTextArea().isEnabled() && !isAltControlOrMetaDown&& isNoteworthyKeyPressed) {
    Selection selection=getTextArea().getDocument().getSelection();
    if (selection.getRangeCount() > 0) {
      Range range=selection.getRangeAt(0);
      logRange(range);
      List<Integer> path=getLocator(range.getStartContainer());
      clientJupiter.generate(new TreeInsertText(clientJupiter.getSiteId(),range.getStartOffset(),convertPath(path),new String(new int[]{event.getUnicodeCharCode()},0,1).charAt(0)));
    }
  }
}
Program: 178485
Project: 178485
Buggy source:
/** 
 * Adds the underlying style to the given text node.
 * @param text           the target text node
 * @param firstCharIndex the first character on which we apply the style
 * @param lastCharIndex  the last character on which we apply the style
 * @return a text fragment indicating what has been formatted
 */
protected TextFragment addStyle(Text text,int firstCharIndex,int lastCharIndex){
  log.info("String_Node_Str");
  if (matchesStyle(text)) {
    return new TextFragment(text,firstCharIndex,lastCharIndex);
  }
  text.crop(firstCharIndex,lastCharIndex);
  Element element=(Element)text.getParentElement();
  element.getStyle().setProperty(getProperty().getJSName(),propertyValue);
  return new TextFragment(text,0,text.getLength());
}

Fixed version (ground truth):
/** 
 * Adds the underlying style to the given text node.
 * @param text           the target text node
 * @param firstCharIndex the first character on which we apply the style
 * @param lastCharIndex  the last character on which we apply the style
 * @return a text fragment indicating what has been formatted
 */
protected TextFragment addStyle(Text text,int firstCharIndex,int lastCharIndex){
  if (matchesStyle(text)) {
    return new TextFragment(text,firstCharIndex,lastCharIndex);
  }
  text.crop(firstCharIndex,lastCharIndex);
  Element element=(Element)text.getParentElement();
  if ("String_Node_Str".equalsIgnoreCase(element.getNodeName())) {
    element.getStyle().setProperty(getProperty().getJSName(),propertyValue);
  }
 else {
    text.removeFromParent();
    SpanElement spanElement=Document.get().createSpanElement();
    spanElement.setAttribute(getProperty().getJSName(),propertyValue);
    spanElement.appendChild(text);
    element.appendChild(spanElement);
  }
  return new TextFragment(text,0,text.getLength());
}
Program: 178486
Project: 178486
Buggy source:
/** 
 * Creates a new executable of this type.
 * @param document the document target
 * @param propertyName the style property name
 * @param propertyValue the style property value
 */
public DomStyleExecutable(Document document,Property propertyName,String propertyValue){
  super(new RichTextArea(),propertyName,propertyValue,TAG_NAME);
  this.document=document;
  this.propertyValue=propertyValue;
  log.info("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Creates a new executable of this type.
 * @param document the document target
 * @param propertyName the style property name
 * @param propertyValue the style property value
 */
public DomStyleExecutable(Document document,Property propertyName,String propertyValue){
  super(new RichTextArea(),propertyName,propertyValue,TAG_NAME);
  this.document=document;
  this.propertyValue=propertyValue;
}
Program: 178488
Project: 178488
Buggy source:
/** 
 * {@inheritDoc}
 * @see KeyPressHandler#onKeyPress(KeyPressEvent)
 */
public void onKeyPress(KeyPressEvent event){
  log.info("String_Node_Str" + getTextArea().getHTML());
  log.info("String_Node_Str" + event.getCharCode() + "String_Node_Str"+ event.getNativeEvent().getKeyCode()+ "String_Node_Str"+ event.getUnicodeCharCode());
  boolean isAltControlOrMetaDown=event.isAltKeyDown() || event.isControlKeyDown() || event.isMetaKeyDown();
  boolean isNoteworthyKeyPressed=event.getCharCode() != '\u0000';
  if (getTextArea().isAttached() && getTextArea().isEnabled() && !isAltControlOrMetaDown&& isNoteworthyKeyPressed) {
    Selection selection=getTextArea().getDocument().getSelection();
    if (selection.getRangeCount() > 0) {
      Range range=selection.getRangeAt(0);
      OperationTarget target=getTarget(range);
      log.info("String_Node_Str" + target);
      List<Integer> path=target.getStartContainer();
      clientJupiter.generate(new TreeInsertText(clientJupiter.getSiteId(),target.getStartOffset(),convertPath(path),new String(new int[]{event.getUnicodeCharCode()},0,1).charAt(0)));
    }
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 * @see KeyPressHandler#onKeyPress(KeyPressEvent)
 */
public void onKeyPress(KeyPressEvent event){
  log.info("String_Node_Str" + getTextArea().getHTML());
  log.fine("String_Node_Str" + event.getCharCode() + "String_Node_Str"+ event.getNativeEvent().getKeyCode()+ "String_Node_Str"+ event.getUnicodeCharCode());
  boolean isAltControlOrMetaDown=event.isAltKeyDown() || event.isControlKeyDown() || event.isMetaKeyDown();
  boolean isNoteworthyKeyPressed=event.getCharCode() != '\u0000';
  if (getTextArea().isAttached() && getTextArea().isEnabled() && !isAltControlOrMetaDown&& isNoteworthyKeyPressed) {
    Selection selection=getTextArea().getDocument().getSelection();
    if (selection.getRangeCount() > 0) {
      Range range=selection.getRangeAt(0);
      doStuff(range);
      OperationTarget target=getTarget(range);
      List<Integer> path=target.getStartContainer();
      clientJupiter.generate(new TreeInsertText(clientJupiter.getSiteId(),target.getStartOffset(),convertPath(path),new String(new int[]{event.getUnicodeCharCode()},0,1).charAt(0)));
    }
  }
}
Program: 178489
Project: 178489
Buggy source:
/** 
 * {@inheritDoc}
 * @see CommandListener#onBeforeCommand(CommandManager,Command,String)
 */
public boolean onBeforeCommand(CommandManager sender,Command command,String param){
  commandOperationCall=null;
  if (getTextArea().isAttached() && getTextArea().isEnabled() && !IGNORED_COMMANDS.contains(command)) {
    Selection selection=getTextArea().getDocument().getSelection();
    if (selection.getRangeCount() > 0) {
      Range range=selection.getRangeAt(0);
      commandOperationCall=new OperationCall(command.toString(),param,getTarget(range));
      log.info(commandOperationCall.toString());
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 * @see CommandListener#onBeforeCommand(CommandManager,Command,String)
 */
public boolean onBeforeCommand(CommandManager sender,Command command,String param){
  commandOperationCall=null;
  if (getTextArea().isAttached() && getTextArea().isEnabled() && !IGNORED_COMMANDS.contains(command)) {
    Selection selection=getTextArea().getDocument().getSelection();
    if (selection.getRangeCount() > 0) {
      Range range=selection.getRangeAt(0);
      commandOperationCall=new OperationCall(command.toString(),param,getTarget(range));
      log.info(commandOperationCall.toString());
      String realTag="String_Node_Str";
      if ("String_Node_Str".equals(command.toString())) {
        realTag="String_Node_Str";
      }
 else       if ("String_Node_Str".equals(command.toString())) {
        realTag="String_Node_Str";
      }
 else       if ("String_Node_Str".equals(command.toString())) {
        realTag="String_Node_Str";
      }
 else       if ("String_Node_Str".equals(command.toString())) {
        realTag="String_Node_Str";
      }
      final OperationTarget target=getTarget(range);
      int[] path=convertPath(target.getStartContainer());
      boolean addStyle=true;
      if (path.length == 2) {
        addStyle=true;
      }
 else {
        addStyle=false;
      }
      int start=range.getStartOffset();
      boolean splitLeft;
      if (start == 0) {
        splitLeft=false;
      }
 else {
        splitLeft=true;
      }
      Text textNode=Text.as(TreeHelper.getChildNodeFromLocator(bodyNode,convertPath(target.getStartContainer())));
      boolean splitRight;
      int end=range.getEndOffset();
      if (end == textNode.getLength()) {
        splitRight=false;
      }
 else {
        splitRight=true;
      }
      TreeOperation op=new TreeStyle(clientJupiter.getSiteId(),path,start,end,realTag,"String_Node_Str",addStyle,splitLeft,splitRight);
      clientJupiter.generate(op);
    }
  }
  return false;
}
Program: 178490
Project: 178490
Buggy source:
/** 
 * Inserts BR elements into the empty P elements
 * @param node the root node to start inserting
 */
private void insertBrInEmptyParagraphs(Node node){
  if (node == null || !Element.is(node)) {
    return;
  }
  if (node.getNodeName().equalsIgnoreCase("String_Node_Str") && node.getChildCount() == 0) {
    node.appendChild(com.google.gwt.dom.client.Document.get().createBRElement());
  }
  NodeList children=node.getChildNodes();
  for (int i=0; i < children.getLength(); i++) {
    insertBrInEmptyParagraphs(children.getItem(i));
  }
}

Fixed version (ground truth):
/** 
 * Inserts BR elements into the empty P elements
 * @param node the root node to start inserting
 */
private void insertBrInEmptyParagraphs(Node node){
  if (node == null || !Element.is(node)) {
    return;
  }
  if (node.getNodeName().equalsIgnoreCase("String_Node_Str") && node.getChildCount() == 0) {
    node.appendChild(Document.get().createBRElement());
  }
  NodeList children=node.getChildNodes();
  for (int i=0; i < children.getLength(); i++) {
    insertBrInEmptyParagraphs(children.getItem(i));
  }
}
Program: 178492
Project: 178492
Buggy source:
@Override public void onConnected(ClientDTO dto,Document document,boolean updateUI){
  if (updateUI) {
    log.finest("String_Node_Str" + Element.as(nativeNode).getString());
    Node newNode=Converter.fromCustomToNative(((TreeDocument)document).getRoot());
    insertBrInEmptyParagraphs(newNode);
    nativeNode.getParentNode().replaceChild(newNode,nativeNode);
    nativeNode=newNode;
    log.finest("String_Node_Str" + Element.as(nativeNode).getString());
  }
}

Fixed version (ground truth):
@Override public void onConnected(ClientDTO dto,fr.loria.score.jupiter.model.Document document,boolean updateUI){
  if (updateUI) {
    log.finest("String_Node_Str" + Element.as(nativeNode).getString());
    Node newNode=Converter.fromCustomToNative(((TreeDocument)document).getRoot());
    insertBrInEmptyParagraphs(newNode);
    nativeNode.getParentNode().replaceChild(newNode,nativeNode);
    nativeNode=newNode;
    log.finest("String_Node_Str" + Element.as(nativeNode).getString());
  }
}
Program: 178493
Project: 178493
Buggy source:
public void execute(Tree root){
  Tree tree=root.getChildFromPath(path);
  if ((tree == root) || (path.length == 1 && position == 0)) {
    if (tree.getChild(0) == null) {
      tree.addChild(TreeFactory.createTextTree(String.valueOf(text)));
      return;
    }
 else {
      tree=tree.getChild(0);
    }
  }
  tree.addChar(text,position);
}

Fixed version (ground truth):
public void execute(Tree root){
  Tree tree=root.getChildFromPath(path);
  final Integer treeType=Integer.valueOf(tree.getAttribute(Tree.NODE_TYPE));
  if (Tree.ELEMENT_NODE == treeType) {
    tree.addChild(TreeFactory.createTextTree(String.valueOf(text)),position);
  }
 else   if (Tree.TEXT_NODE == treeType) {
    tree.addChar(text,position);
  }
}
Program: 178494
Project: 178494
Buggy source:
public String toString(){
  return "String_Node_Str" + super.toString() + "String_Node_Str"+ start+ "String_Node_Str"+ end+ "String_Node_Str"+ param+ "String_Node_Str"+ value+ "String_Node_Str";
}

Fixed version (ground truth):
public String toString(){
  return "String_Node_Str" + super.toString() + "String_Node_Str"+ start+ "String_Node_Str"+ end+ "String_Node_Str"+ param+ "String_Node_Str"+ value+ "String_Node_Str"+ addStyle+ "String_Node_Str"+ splitLeft+ "String_Node_Str"+ splitRight+ "String_Node_Str";
}
Program: 178497
Project: 178497
Buggy source:
/** 
 * {@inheritDoc}
 * @see AbstractPlugin#init(RichTextArea,Config)
 */
public void init(RichTextArea textArea,Config config){
  super.init(textArea,config);
  saveRegistration(textArea.addKeyDownHandler(this));
  saveRegistration(textArea.addKeyPressHandler(this));
  saveRegistration(textArea.addKeyUpHandler(this));
  getTextArea().getCommandManager().addCommandListener(this);
  bodyNode=textArea.getDocument().getBody();
  final Element p=Document.get().createElement("String_Node_Str");
  if (bodyNode.getChildCount() == 0) {
    bodyNode.insertFirst(p);
  }
 else   if (bodyNode.getChildCount() == 1 && bodyNode.getFirstChild().getNodeName().equalsIgnoreCase("String_Node_Str")) {
    bodyNode.insertBefore(p,bodyNode.getFirstChild());
  }
  Tree t=Converter.fromNativeToCustom(Element.as(bodyNode));
  clientJupiter=new ClientJupiterAlg(new TreeDocument(t));
  clientJupiter.setEditingSessionId(Integer.parseInt(config.getParameter(RtApi.DOCUMENT_ID)));
  clientJupiter.setCommunicationService(CommunicationService.ServiceHelper.getCommunicationService());
  clientJupiter.setCallback(new TreeClientCallback(bodyNode));
  clientJupiter.connect();
  customizeActionListeners();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 * @see AbstractPlugin#init(RichTextArea,Config)
 */
public void init(RichTextArea textArea,Config config){
  super.init(textArea,config);
  saveRegistration(textArea.addKeyDownHandler(this));
  saveRegistration(textArea.addKeyPressHandler(this));
  saveRegistration(textArea.addKeyUpHandler(this));
  getTextArea().getCommandManager().addCommandListener(this);
  Node bodyNode=textArea.getDocument().getBody();
  final Element p=Document.get().createElement("String_Node_Str");
  if (bodyNode.getChildCount() == 0) {
    bodyNode.insertFirst(p);
  }
 else   if (bodyNode.getChildCount() == 1 && bodyNode.getFirstChild().getNodeName().equalsIgnoreCase("String_Node_Str")) {
    bodyNode.insertBefore(p,bodyNode.getFirstChild());
  }
  Tree t=Converter.fromNativeToCustom(Element.as(bodyNode));
  clientJupiter=new ClientJupiterAlg(new TreeDocument(t));
  clientJupiter.setEditingSessionId(Integer.parseInt(config.getParameter(RtApi.DOCUMENT_ID)));
  clientJupiter.setCommunicationService(CommunicationService.ServiceHelper.getCommunicationService());
  clientJupiter.setCallback(new TreeClientCallback(bodyNode));
  clientJupiter.connect();
  customizeActionListeners();
}