Program: 79899
Project: 79899
Buggy source:
/** 
 * Format the given LogRecord and return back a formatted String. <p> The formatted String has the values of the fields which are selected and NULL if any field is not selected. All fields are enclosed in single- quotes. <p> A typical formatted string can be given as follows: '10:10:10', '10th June, 2002', 'NULL', 'NULL', 'Session Created Successfull', 'INFO', 'NULL', 'NULL' <p> This formatted string will be enclosed within braces by Handler to construct the query string.
 * @param logRecord the log record to be formatted.
 * @return formatted string.
 */
public String format(java.util.logging.LogRecord logRecord){
  Map logInfoTable=null;
  if ((LogManagerUtil.isAMLoggingMode()) && (logRecord instanceof com.sun.identity.log.ILogRecord)) {
    logInfoTable=((com.sun.identity.log.ILogRecord)logRecord).getLogInfoMap();
  }
  StringBuilder sbuffer=new StringBuilder();
  String strTime;
  if (secureTimestampGenerator != null) {
    strTime=secureTimestampGenerator.getTimestamp();
  }
 else {
    strTime="String_Node_Str";
  }
  String toDate=null;
  if (!isMySQL) {
    toDate="String_Node_Str";
  }
 else {
    toDate="String_Node_Str";
  }
  sbuffer.append(toDate);
  sbuffer.append(strTime);
  sbuffer.append("String_Node_Str");
  sbuffer.append(dateTimeFormat);
  sbuffer.append("String_Node_Str");
  String tstr=formatMessage(logRecord);
  if ((tstr == null) || (tstr.length() <= 0)) {
    tstr=LogConstants.NOTAVAIL;
  }
 else   if (tstr.length() > 0) {
    String str1=tstr;
    if (tstr.indexOf("String_Node_Str") != -1) {
      str1=checkEscapes(tstr,"String_Node_Str","String_Node_Str");
    }
    String str2=str1;
    if (isMySQL) {
      if (str1.indexOf("String_Node_Str") != -1) {
        str2=checkEscapes(str1,"String_Node_Str","String_Node_Str");
      }
    }
    tstr=str2;
  }
  sbuffer.append("String_Node_Str").append(tstr).append("String_Node_Str");
  if (Debug.messageEnabled()) {
    Debug.message("String_Node_Str" + sbuffer.toString() + "String_Node_Str");
  }
  String[] allFields=lmanager.getAllFields();
  Set selectedFields=lmanager.getSelectedFieldSet();
  int len=0;
  if (allFields != null) {
    len=allFields.length;
  }
  for (int i=2; i < len - 1; i++) {
    if ((logInfoTable != null) && (selectedFields != null) && (selectedFields.contains(allFields[i]))) {
      String tempstr=(String)logInfoTable.get(allFields[i]);
      if ((tempstr != null) && (tempstr.length() > 0) && (tempstr.indexOf("String_Node_Str") != -1)) {
        StringTokenizer tmps=new StringTokenizer(tempstr,"String_Node_Str");
        StringBuilder thisfield=new StringBuilder();
        if (Debug.messageEnabled()) {
          Debug.message("String_Node_Str" + tempstr);
        }
        if (tempstr.indexOf("String_Node_Str") == 0) {
          thisfield.append("String_Node_Str");
          if (tmps.hasMoreTokens()) {
            thisfield.append(tmps.nextToken());
          }
        }
 else {
          if (tmps.hasMoreTokens()) {
            thisfield.append(tmps.nextToken());
          }
        }
        while (tmps.hasMoreTokens()) {
          thisfield.append("String_Node_Str").append(tmps.nextToken());
        }
        if (tempstr.indexOf("String_Node_Str",tempstr.length() - 1) != -1) {
          thisfield.append("String_Node_Str");
        }
        tempstr=thisfield.toString();
      }
      if (tempstr == null) {
        tempstr=LogConstants.NOTAVAIL;
      }
      sbuffer.append("String_Node_Str").append(tempstr).append("String_Node_Str");
    }
 else {
      sbuffer.append("String_Node_Str").append(LogConstants.NOTAVAIL).append("String_Node_Str").append("String_Node_Str");
    }
  }
  if (Debug.messageEnabled()) {
    Debug.message("String_Node_Str" + sbuffer.toString());
  }
  if ((selectedFields != null) && (logInfoTable != null) && (selectedFields.contains(allFields[len - 1]))) {
    String tmpstr=(String)logInfoTable.get(allFields[len - 1]);
    if (tmpstr == null) {
      tmpstr=LogConstants.NOTAVAIL;
    }
    sbuffer.append("String_Node_Str").append(tmpstr).append("String_Node_Str");
  }
 else {
    sbuffer.append("String_Node_Str").append(LogConstants.NOTAVAIL).append("String_Node_Str");
  }
  if (Debug.messageEnabled()) {
    Debug.message("String_Node_Str" + sbuffer.toString());
  }
  return sbuffer.toString();
}

Fixed version (ground truth):
/** 
 * Format the given LogRecord and return back a formatted String. <p> The formatted String has the values of the fields which are selected and NULL if any field is not selected. All fields are enclosed in single- quotes. <p> A typical formatted string can be given as follows: '10:10:10', '10th June, 2002', 'NULL', 'NULL', 'Session Created Successfull', 'INFO', 'NULL', 'NULL' <p> This formatted string will be enclosed within braces by Handler to construct the query string.
 * @param logRecord the log record to be formatted.
 * @return formatted string.
 */
public String format(java.util.logging.LogRecord logRecord){
  Map logInfoTable=null;
  if ((LogManagerUtil.isAMLoggingMode()) && (logRecord instanceof com.sun.identity.log.ILogRecord)) {
    logInfoTable=((com.sun.identity.log.ILogRecord)logRecord).getLogInfoMap();
  }
  StringBuilder sbuffer=new StringBuilder();
  String strTime;
  if (secureTimestampGenerator != null) {
    strTime=secureTimestampGenerator.getTimestamp();
  }
 else {
    strTime="String_Node_Str";
  }
  String toDate=null;
  if (!isMySQL) {
    toDate="String_Node_Str";
  }
 else {
    toDate="String_Node_Str";
  }
  sbuffer.append(toDate);
  sbuffer.append(strTime);
  sbuffer.append("String_Node_Str");
  sbuffer.append(dateTimeFormat);
  sbuffer.append("String_Node_Str");
  String tstr=formatMessage(logRecord);
  if ((tstr == null) || (tstr.length() <= 0)) {
    tstr=LogConstants.NOTAVAIL;
  }
 else   if (tstr.length() > 0) {
    String str1=tstr;
    if (tstr.indexOf("String_Node_Str") != -1) {
      str1=checkEscapes(tstr,"String_Node_Str","String_Node_Str");
    }
    String str2=str1;
    if (isMySQL) {
      if (str1.indexOf("String_Node_Str") != -1) {
        str2=checkEscapes(str1,"String_Node_Str","String_Node_Str");
      }
    }
 else {
      int splitLength=MAX_LITERAL_LENGTH / 4;
      if (str1.length() >= splitLength) {
        StringBuilder strBuilder=new StringBuilder();
        int beginIndex=0;
        int endIndex=splitLength;
        if (str1.length() >= splitLength) {
          strBuilder.append("String_Node_Str");
          while (str1.length() > beginIndex) {
            if (endIndex > str1.length()) {
              endIndex=str1.length();
            }
            strBuilder.append("String_Node_Str");
            strBuilder.append(str1.substring(beginIndex,endIndex));
            strBuilder.append("String_Node_Str");
            beginIndex=beginIndex + splitLength;
            endIndex=endIndex + splitLength;
          }
          strBuilder.append("String_Node_Str");
        }
        str2=strBuilder.toString();
      }
    }
    tstr=str2;
  }
  sbuffer.append("String_Node_Str").append(tstr).append("String_Node_Str");
  if (Debug.messageEnabled()) {
    Debug.message("String_Node_Str" + sbuffer.toString() + "String_Node_Str");
  }
  String[] allFields=lmanager.getAllFields();
  Set selectedFields=lmanager.getSelectedFieldSet();
  int len=0;
  if (allFields != null) {
    len=allFields.length;
  }
  for (int i=2; i < len - 1; i++) {
    if ((logInfoTable != null) && (selectedFields != null) && (selectedFields.contains(allFields[i]))) {
      String tempstr=(String)logInfoTable.get(allFields[i]);
      if ((tempstr != null) && (tempstr.length() > 0) && (tempstr.indexOf("String_Node_Str") != -1)) {
        StringTokenizer tmps=new StringTokenizer(tempstr,"String_Node_Str");
        StringBuilder thisfield=new StringBuilder();
        if (Debug.messageEnabled()) {
          Debug.message("String_Node_Str" + tempstr);
        }
        if (tempstr.indexOf("String_Node_Str") == 0) {
          thisfield.append("String_Node_Str");
          if (tmps.hasMoreTokens()) {
            thisfield.append(tmps.nextToken());
          }
        }
 else {
          if (tmps.hasMoreTokens()) {
            thisfield.append(tmps.nextToken());
          }
        }
        while (tmps.hasMoreTokens()) {
          thisfield.append("String_Node_Str").append(tmps.nextToken());
        }
        if (tempstr.indexOf("String_Node_Str",tempstr.length() - 1) != -1) {
          thisfield.append("String_Node_Str");
        }
        tempstr=thisfield.toString();
      }
      if (tempstr == null) {
        tempstr=LogConstants.NOTAVAIL;
      }
      sbuffer.append("String_Node_Str").append(tempstr).append("String_Node_Str");
    }
 else {
      sbuffer.append("String_Node_Str").append(LogConstants.NOTAVAIL).append("String_Node_Str").append("String_Node_Str");
    }
  }
  if (Debug.messageEnabled()) {
    Debug.message("String_Node_Str" + sbuffer.toString());
  }
  if ((selectedFields != null) && (logInfoTable != null) && (selectedFields.contains(allFields[len - 1]))) {
    String tmpstr=(String)logInfoTable.get(allFields[len - 1]);
    if (tmpstr == null) {
      tmpstr=LogConstants.NOTAVAIL;
    }
    sbuffer.append("String_Node_Str").append(tmpstr).append("String_Node_Str");
  }
 else {
    sbuffer.append("String_Node_Str").append(LogConstants.NOTAVAIL).append("String_Node_Str");
  }
  if (Debug.messageEnabled()) {
    Debug.message("String_Node_Str" + sbuffer.toString());
  }
  return sbuffer.toString();
}