Program: 89766
Project: 89766
Buggy source:
/** 
 * Builds a query to fetch jobs according to selection criteria.
 * @param query the selection criteria.
 * @param count build a count query instead of selecting columns.
 * @return the proper SQL query.
 */
private String buildSqlQuery(HarvestStatusQuery query,boolean count){
  StringBuffer sql=new StringBuffer("String_Node_Str");
  if (count) {
    sql.append("String_Node_Str");
  }
 else {
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
  }
  sql.append("String_Node_Str");
  sql.append("String_Node_Str");
  JobStatus[] jobStatuses=query.getSelectedJobStatuses();
  if (jobStatuses.length > 0) {
    if (jobStatuses.length == 1) {
      int statusOrdinal=jobStatuses[0].ordinal();
      sql.append("String_Node_Str");
      sql.append(statusOrdinal);
    }
 else {
      sql.append("String_Node_Str");
      sql.append(jobStatuses[0].ordinal());
      for (int i=1; i < jobStatuses.length; i++) {
        sql.append("String_Node_Str");
        sql.append(jobStatuses[i].ordinal());
      }
      sql.append("String_Node_Str");
    }
  }
  String harvestName=query.getHarvestName();
  if (!harvestName.isEmpty()) {
    if (harvestName.indexOf(HarvestStatusQuery.HARVEST_NAME_WILDCARD) == -1) {
      sql.append("String_Node_Str");
      sql.append(harvestName);
      sql.append("String_Node_Str");
    }
 else {
      String harvestNamePattern=harvestName.replaceAll("String_Node_Str","String_Node_Str");
      sql.append("String_Node_Str");
      sql.append(harvestNamePattern);
      sql.append("String_Node_Str");
    }
  }
  Long harvestRun=query.getHarvestRunNumber();
  if (harvestRun != null) {
    sql.append("String_Node_Str" + harvestRun);
  }
  Long harvestId=query.getHarvestId();
  if (harvestId != null) {
    sql.append("String_Node_Str" + harvestId);
  }
  long startDate=query.getStartDate();
  if (startDate != HarvestStatusQuery.DATE_NONE) {
    sql.append("String_Node_Str");
    sql.append(new java.sql.Date(startDate).toString());
    sql.append("String_Node_Str");
  }
  long endDate=query.getEndDate();
  if (endDate != HarvestStatusQuery.DATE_NONE) {
    sql.append("String_Node_Str");
    sql.append(new java.sql.Date(endDate).toString());
    sql.append("String_Node_Str");
  }
  if (!count) {
    sql.append("String_Node_Str");
    if (!query.isSortAscending()) {
      sql.append("String_Node_Str" + SORT_ORDER.DESC.name());
    }
 else {
      sql.append("String_Node_Str" + SORT_ORDER.ASC.name());
    }
    long pagesize=query.getPageSize();
    if (pagesize != HarvestStatusQuery.PAGE_SIZE_NONE) {
      sql.append("String_Node_Str" + DBSpecifics.getInstance().getOrderByLimitAndOffsetSubClause(pagesize,(query.getStartPageIndex() - 1) * pagesize));
    }
  }
  return sql.toString();
}

Fixed version (ground truth):
/** 
 * Builds a query to fetch jobs according to selection criteria.
 * @param query the selection criteria.
 * @param count build a count query instead of selecting columns.
 * @return the proper SQL query.
 */
private HarvestStatusQueryBuilder buildSqlQuery(HarvestStatusQuery query,boolean count){
  HarvestStatusQueryBuilder sq=new HarvestStatusQueryBuilder();
  StringBuffer sql=new StringBuffer("String_Node_Str");
  if (count) {
    sql.append("String_Node_Str");
  }
 else {
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
  }
  sql.append("String_Node_Str");
  sql.append("String_Node_Str");
  JobStatus[] jobStatuses=query.getSelectedJobStatuses();
  if (jobStatuses.length > 0) {
    if (jobStatuses.length == 1) {
      int statusOrdinal=jobStatuses[0].ordinal();
      sql.append("String_Node_Str");
      sq.addParameter(Integer.class,statusOrdinal);
    }
 else {
      sql.append("String_Node_Str");
      sql.append(jobStatuses[0].ordinal());
      for (int i=1; i < jobStatuses.length; i++) {
        sql.append("String_Node_Str");
        sq.addParameter(Integer.class,jobStatuses[i].ordinal());
      }
      sql.append("String_Node_Str");
    }
  }
  String harvestName=query.getHarvestName();
  if (!harvestName.isEmpty()) {
    if (harvestName.indexOf(HarvestStatusQuery.HARVEST_NAME_WILDCARD) == -1) {
      sql.append("String_Node_Str");
      sq.addParameter(String.class,harvestName);
    }
 else {
      String harvestNamePattern=harvestName.replaceAll("String_Node_Str","String_Node_Str");
      sql.append("String_Node_Str");
      sq.addParameter(String.class,harvestNamePattern);
    }
  }
  Long harvestRun=query.getHarvestRunNumber();
  if (harvestRun != null) {
    sql.append("String_Node_Str");
    sq.addParameter(Long.class,harvestRun);
  }
  Long harvestId=query.getHarvestId();
  if (harvestId != null) {
    sql.append("String_Node_Str");
    sq.addParameter(Long.class,harvestId);
  }
  long startDate=query.getStartDate();
  if (startDate != HarvestStatusQuery.DATE_NONE) {
    sql.append("String_Node_Str");
    sq.addParameter(java.sql.Date.class,new java.sql.Date(startDate));
  }
  long endDate=query.getEndDate();
  if (endDate != HarvestStatusQuery.DATE_NONE) {
    sql.append("String_Node_Str");
    sq.addParameter(java.sql.Date.class,new java.sql.Date(endDate));
  }
  if (!count) {
    sql.append("String_Node_Str");
    if (!query.isSortAscending()) {
      sql.append("String_Node_Str" + SORT_ORDER.DESC.name());
    }
 else {
      sql.append("String_Node_Str" + SORT_ORDER.ASC.name());
    }
    long pagesize=query.getPageSize();
    if (pagesize != HarvestStatusQuery.PAGE_SIZE_NONE) {
      sql.append("String_Node_Str" + DBSpecifics.getInstance().getOrderByLimitAndOffsetSubClause(pagesize,(query.getStartPageIndex() - 1) * pagesize));
    }
  }
  sq.setSqlString(sql.toString());
  return sq;
}