Program: 79880
Project: 79880
Buggy source:
public static String formatTextWithReplacements(String text,Map<String,String> replacements,String newline,String extraline,String newpara,int maxLineLength,StringSizeDeterminer ssd){
  boolean endsWithPara=false;
  if (text.endsWith(newpara)) {
    endsWithPara=true;
    text=text.substring(0,text.length() - newpara.length());
  }
  text=text.replace(newline,"String_Node_Str").replace(extraline,"String_Node_Str");
  if (replacements != null) {
    int index=0;
    for (    Map.Entry<String,String> toReplace : replacements.entrySet()) {
      index++;
      text=text.replace(toReplace.getKey(),"String_Node_Str" + index + "String_Node_Str");
    }
    index=0;
    for (    Map.Entry<String,String> toReplace : replacements.entrySet()) {
      index++;
      text=text.replace("String_Node_Str" + index + "String_Node_Str",toReplace.getValue());
    }
  }
  String[] oldParagraphs=text.split(newpara.replace("String_Node_Str","String_Node_Str"));
  StringBuilder finalResult=new StringBuilder();
  int sentenceNewLineSize=Math.max(10,maxLineLength / 2);
  for (int para=0; para < oldParagraphs.length; para++) {
    String[] words=oldParagraphs[para].split("String_Node_Str");
    StringBuilder fullPara=new StringBuilder();
    StringBuilder thisLine=new StringBuilder();
    int currLineWC=0;
    int currLineCC=0;
    int linesWritten=0;
    char currLineLastChar=0;
    for (int i=0; i < words.length; i++) {
      int reqLength=ssd.lengthFor(words[i]);
      if (currLineWC > 0) {
        reqLength++;
      }
      if ((currLineCC + reqLength > maxLineLength) || (currLineCC >= sentenceNewLineSize && (currLineLastChar == '.' || currLineLastChar == '?' || currLineLastChar == '!' || currLineLastChar == '…' || currLineLastChar == ','))) {
        if (currLineWC > 0) {
          if (linesWritten > 1) {
            fullPara.append(extraline);
          }
 else           if (linesWritten == 1) {
            fullPara.append(newline);
          }
          fullPara.append(thisLine.toString());
          linesWritten++;
          thisLine=new StringBuilder();
        }
        thisLine.append(words[i]);
        currLineWC=1;
        currLineCC=ssd.lengthFor(words[i]);
        currLineLastChar=words[i].charAt(words[i].length() - 1);
      }
 else {
        if (currLineWC > 0) {
          thisLine.append(' ');
        }
        thisLine.append(words[i]);
        currLineWC++;
        currLineCC+=reqLength;
        currLineLastChar=words[i].charAt(words[i].length() - 1);
      }
    }
    if (currLineWC > 0) {
      if (linesWritten > 1) {
        fullPara.append(extraline);
      }
 else       if (linesWritten == 1) {
        fullPara.append(newline);
      }
      fullPara.append(thisLine.toString());
      linesWritten++;
    }
    if (para > 0) {
      finalResult.append(newpara);
    }
    finalResult.append(fullPara.toString());
  }
  if (endsWithPara) {
    finalResult.append(newpara);
  }
  return finalResult.toString();
}

Fixed version (ground truth):
public static String formatTextWithReplacements(String text,Map<String,String> replacements,String newline,String extraline,String newpara,int maxLineLength,StringSizeDeterminer ssd){
  boolean endsWithPara=false;
  if (text.endsWith(newpara)) {
    endsWithPara=true;
    text=text.substring(0,text.length() - newpara.length());
  }
  text=text.replace(newline,"String_Node_Str").replace(extraline,"String_Node_Str");
  if (replacements != null) {
    int index=0;
    for (    Map.Entry<String,String> toReplace : replacements.entrySet()) {
      index++;
      text=text.replace(toReplace.getKey(),"String_Node_Str" + index + "String_Node_Str");
    }
    index=0;
    for (    Map.Entry<String,String> toReplace : replacements.entrySet()) {
      index++;
      text=text.replace("String_Node_Str" + index + "String_Node_Str",toReplace.getValue());
    }
  }
  String[] oldParagraphs=text.split(newpara.replace("String_Node_Str","String_Node_Str"));
  StringBuilder finalResult=new StringBuilder();
  int sentenceNewLineSize=Math.max(10,maxLineLength / 2);
  for (int para=0; para < oldParagraphs.length; para++) {
    String[] words=oldParagraphs[para].split("String_Node_Str");
    StringBuilder fullPara=new StringBuilder();
    StringBuilder thisLine=new StringBuilder();
    int currLineWC=0;
    int currLineCC=0;
    int linesWritten=0;
    char currLineLastChar=0;
    for (int i=0; i < words.length; i++) {
      int reqLength=ssd.lengthFor(words[i]);
      if (currLineWC > 0) {
        reqLength++;
      }
      if ((currLineCC + reqLength > maxLineLength) || (currLineCC >= sentenceNewLineSize && (currLineLastChar == '.' || currLineLastChar == '?' || currLineLastChar == '!' || currLineLastChar == '…' || currLineLastChar == ','))) {
        if (currLineWC > 0) {
          if (linesWritten > 1) {
            fullPara.append(extraline);
          }
 else           if (linesWritten == 1) {
            fullPara.append(newline);
          }
          fullPara.append(thisLine.toString());
          linesWritten++;
          thisLine=new StringBuilder();
        }
        thisLine.append(words[i]);
        currLineWC=1;
        currLineCC=ssd.lengthFor(words[i]);
        if (words[i].length() == 0) {
          currLineLastChar=0;
        }
 else {
          currLineLastChar=words[i].charAt(words[i].length() - 1);
        }
      }
 else {
        if (currLineWC > 0) {
          thisLine.append(' ');
        }
        thisLine.append(words[i]);
        currLineWC++;
        currLineCC+=reqLength;
        if (words[i].length() == 0) {
          currLineLastChar=0;
        }
 else {
          currLineLastChar=words[i].charAt(words[i].length() - 1);
        }
      }
    }
    if (currLineWC > 0) {
      if (linesWritten > 1) {
        fullPara.append(extraline);
      }
 else       if (linesWritten == 1) {
        fullPara.append(newline);
      }
      fullPara.append(thisLine.toString());
      linesWritten++;
    }
    if (para > 0) {
      finalResult.append(newpara);
    }
    finalResult.append(fullPara.toString());
  }
  if (endsWithPara) {
    finalResult.append(newpara);
  }
  return finalResult.toString();
}