Program: 101570
Project: 101570
Buggy source:
/** 
 * Merge a set of patches onto the text.  Return a patched text, as well as an array of true/false values indicating which patches were applied.
 * @param patches Array of patch objects
 * @param text Old text
 * @return the patch result
 */
public PatchResults apply(String text){
  splitMax();
  boolean[] results=new boolean[patches.size()];
  String resultText=text;
  int delta=0;
  int expectedLoc=0;
  int startLoc=-1;
  String text1="String_Node_Str";
  String text2="String_Node_Str";
  List diffs;
  int index1=0;
  int index2=0;
  int x=0;
  Iterator patchIter=patches.iterator();
  while (patchIter.hasNext()) {
    PatchEntry aPatch=(PatchEntry)patchIter.next();
    expectedLoc=aPatch.getTargetStart() + delta;
    text1=aPatch.getSourceText();
    Match match=new Match(resultText,text1,expectedLoc);
    startLoc=match.locate();
    if (startLoc == -1) {
      results[x]=false;
    }
 else {
      results[x]=true;
      delta=startLoc - expectedLoc;
      text2=resultText.substring(startLoc,startLoc + text1.length());
      if (text1.equals(text2)) {
        resultText=resultText.substring(0,startLoc) + aPatch.getTargetText() + resultText.substring(startLoc + text1.length());
      }
 else {
        Diff diff=new Diff(text1,text2,false);
        diffs=diff.compare();
        index1=0;
        Iterator diffIter=aPatch.iterator();
        while (diffIter.hasNext()) {
          Difference aDiff=(Difference)diffIter.next();
          EditType editType=aDiff.getEditType();
          if (!EditType.EQUAL.equals(editType)) {
            index2=diff.xIndex(diffs,index1);
          }
          if (EditType.INSERT.equals(editType)) {
            resultText=resultText.substring(0,startLoc + index2) + aDiff.getText() + resultText.substring(startLoc + index2);
          }
 else           if (EditType.DELETE.equals(editType)) {
            resultText=resultText.substring(0,startLoc + index2) + resultText.substring(startLoc + diff.xIndex(diffs,index1 + aDiff.getText().length()));
          }
          if (!EditType.DELETE.equals(editType)) {
            index1+=aDiff.getText().length();
          }
        }
      }
    }
    x++;
  }
  return new PatchResults(resultText,results);
}

Fixed version (ground truth):
/** 
 * Merge this patch onto the text.  Return a patched text, as well as an array of true/false values indicating which patches were applied.
 * @param text Old text
 * @return the patch result
 */
public PatchResults apply(String text){
  splitMax();
  boolean[] results=new boolean[patches.size()];
  String resultText=text;
  int delta=0;
  int expectedLoc=0;
  int startLoc=-1;
  String text1="String_Node_Str";
  String text2="String_Node_Str";
  List diffs;
  int index1=0;
  int index2=0;
  int x=0;
  Iterator patchIter=patches.iterator();
  while (patchIter.hasNext()) {
    PatchEntry aPatch=(PatchEntry)patchIter.next();
    expectedLoc=aPatch.getTargetStart() + delta;
    text1=aPatch.getSourceText();
    Match match=new Match(resultText,text1,expectedLoc);
    startLoc=match.locate();
    if (startLoc == -1) {
      results[x]=false;
    }
 else {
      results[x]=true;
      delta=startLoc - expectedLoc;
      text2=resultText.substring(startLoc,startLoc + text1.length());
      if (text1.equals(text2)) {
        resultText=resultText.substring(0,startLoc) + aPatch.getTargetText() + resultText.substring(startLoc + text1.length());
      }
 else {
        Diff diff=new Diff(text1,text2,false);
        diffs=diff.compare();
        index1=0;
        Iterator diffIter=aPatch.iterator();
        while (diffIter.hasNext()) {
          Difference aDiff=(Difference)diffIter.next();
          EditType editType=aDiff.getEditType();
          if (!EditType.EQUAL.equals(editType)) {
            index2=diff.xIndex(diffs,index1);
          }
          if (EditType.INSERT.equals(editType)) {
            resultText=resultText.substring(0,startLoc + index2) + aDiff.getText() + resultText.substring(startLoc + index2);
          }
 else           if (EditType.DELETE.equals(editType)) {
            resultText=resultText.substring(0,startLoc + index2) + resultText.substring(startLoc + diff.xIndex(diffs,index1 + aDiff.getText().length()));
          }
          if (!EditType.DELETE.equals(editType)) {
            index1+=aDiff.getText().length();
          }
        }
      }
    }
    x++;
  }
  return new PatchResults(resultText,results);
}