Program: 125291
Project: 125291
Buggy source:
/** 
 * DOC liuwu Comment method "replaceMEMO_SQL". aim: to resolve TDI-7487
 * @param original
 * @return
 */
public static String replaceCRLFInMEMO_SQL(String original){
  if (original == null || original.trim().length() == 0) {
    return original;
  }
  StringBuilder result=new StringBuilder();
  int leftQuotes=original.indexOf("String_Node_Str");
  int rightQuotes=original.indexOf("String_Node_Str",leftQuotes + 1);
  int fakeRightQuotes=getFakeRightQuotes(original,leftQuotes);
  while (rightQuotes == fakeRightQuotes + 1) {
    rightQuotes=original.indexOf("String_Node_Str",rightQuotes + 1);
    fakeRightQuotes=getFakeRightQuotes(original,fakeRightQuotes);
  }
  int leftPrev=0;
  while (leftQuotes >= 0 && rightQuotes > leftQuotes) {
    if (leftQuotes > leftPrev) {
      result.append(original.substring(leftPrev,leftQuotes));
    }
    if (leftQuotes < rightQuotes) {
      int current=leftQuotes;
      while (rightQuotes + 1 - current > 120) {
        int Offset=120;
        while (original.charAt(current + Offset - 1) == '\\') {
          Offset--;
        }
        result.append(original.substring(current,current + Offset).replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str")).append("String_Node_Str");
        current+=Offset;
        Offset=120;
      }
      result.append(original.substring(current,rightQuotes + 1).replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str"));
    }
    leftQuotes=original.indexOf("String_Node_Str",rightQuotes + 1);
    leftPrev=rightQuotes + 1;
    rightQuotes=original.indexOf("String_Node_Str",leftQuotes + 1);
    fakeRightQuotes=getFakeRightQuotes(original,leftQuotes);
    while (rightQuotes == fakeRightQuotes + 1) {
      rightQuotes=original.indexOf("String_Node_Str",rightQuotes + 1);
      fakeRightQuotes=getFakeRightQuotes(original,fakeRightQuotes);
    }
  }
  result.append(original.substring(leftPrev));
  return result.toString();
}

Fixed version (ground truth):
/** 
 * DOC liuwu Comment method "replaceMEMO_SQL". aim: to resolve TDI-7487
 * @param original
 * @return
 */
public static String replaceCRLFInMEMO_SQL(String original){
  if (original == null || original.trim().length() == 0) {
    return original;
  }
  StringBuilder result=new StringBuilder();
  int leftQuotes=original.indexOf("String_Node_Str");
  int rightQuotes=original.indexOf("String_Node_Str",leftQuotes + 1);
  int fakeRightQuotes=getFakeRightQuotes(original,leftQuotes);
  while (rightQuotes == fakeRightQuotes + 1) {
    rightQuotes=original.indexOf("String_Node_Str",rightQuotes + 1);
    fakeRightQuotes=getFakeRightQuotes(original,fakeRightQuotes);
  }
  int leftPrev=0;
  while (leftQuotes >= 0 && rightQuotes > leftQuotes) {
    if (leftQuotes > leftPrev) {
      result.append(original.substring(leftPrev,leftQuotes));
    }
    if (leftQuotes < rightQuotes) {
      int current=leftQuotes;
      int Offset=120;
      int count=0;
      while (rightQuotes + 1 - current > 120) {
        while (original.charAt(current + Offset - 1) == '\\') {
          Offset--;
        }
        if (count > 500) {
          result.append(original.substring(current,current + Offset).replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str")).append("String_Node_Str");
          count=0;
        }
 else {
          result.append(original.substring(current,current + Offset).replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str")).append("String_Node_Str");
        }
        current+=Offset;
        Offset=120;
        count++;
      }
      result.append(original.substring(current,rightQuotes + 1).replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str"));
    }
    leftQuotes=original.indexOf("String_Node_Str",rightQuotes + 1);
    leftPrev=rightQuotes + 1;
    rightQuotes=original.indexOf("String_Node_Str",leftQuotes + 1);
    fakeRightQuotes=getFakeRightQuotes(original,leftQuotes);
    while (rightQuotes == fakeRightQuotes + 1) {
      rightQuotes=original.indexOf("String_Node_Str",rightQuotes + 1);
      fakeRightQuotes=getFakeRightQuotes(original,fakeRightQuotes);
    }
  }
  result.append(original.substring(leftPrev));
  return result.toString();
}