Program: 140234
Project: 140234
Buggy source:
/** 
 * Method "addWhereToStatement".
 * @param statement a statement already prepared for parsing
 * @param whereClause
 * @return the new statement
 */
public String addWhereToStatement(String statement,String whereClause){
  if (!isTooComplexForZql(statement)) {
    try {
      ZQuery query=this.parseQuery(statement);
      if (whereClause != null) {
        if (StringUtils.isNotBlank(whereClause)) {
          String safeWhereClause=replaceUnsupportedQuotes(whereClause);
          ZqlParser filterParser=getZqlParser();
          filterParser.initParser(new ByteArrayInputStream(safeWhereClause.getBytes()));
          ZExp currentWhere=query.getWhere();
          ZExp whereExpression=filterParser.readExpression();
          if (currentWhere != null && whereExpression != null) {
            ZExpression finalWhereExpression=new ZExpression(and(),currentWhere,whereExpression);
            query.addWhere(finalWhereExpression);
          }
 else {
            if (whereExpression != null) {
              query.addWhere(whereExpression);
            }
          }
        }
      }
      return query.toString();
    }
 catch (    ParseException e) {
      log.warn("String_Node_Str" + statement + "String_Node_Str"+ e,e);
    }
  }
  if (statement.contains("String_Node_Str") && statement.contains("String_Node_Str")) {
    int insertIdx=statement.indexOf("String_Node_Str");
    StringBuilder finalQuery=new StringBuilder().append(statement.substring(0,insertIdx)).append(where()).append(surroundWithSpaces(whereClause)).append(statement.substring(insertIdx));
    return finalQuery.toString();
  }
  String op=statement.toUpperCase().contains(where()) ? and() : where();
  String finalQuery=statement + op + whereClause;
  log.warn("String_Node_Str" + finalQuery);
  return finalQuery;
}

Fixed version (ground truth):
/** 
 * Method "addWhereToStatement".
 * @param statement a statement already prepared for parsing
 * @param whereClause
 * @return the new statement
 */
public String addWhereToStatement(String statement,String whereClause){
  if (!isTooComplexForZql(statement)) {
    try {
      ZQuery query=this.parseQuery(statement);
      if (whereClause != null) {
        if (StringUtils.isNotBlank(whereClause)) {
          String safeWhereClause=replaceUnsupportedQuotes(whereClause);
          ZqlParser filterParser=getZqlParser();
          filterParser.initParser(new ByteArrayInputStream(safeWhereClause.getBytes()));
          ZExp currentWhere=query.getWhere();
          ZExp whereExpression=filterParser.readExpression();
          if (currentWhere != null && whereExpression != null) {
            ZExpression finalWhereExpression=new ZExpression(and(),currentWhere,whereExpression);
            query.addWhere(finalWhereExpression);
          }
 else {
            if (whereExpression != null) {
              query.addWhere(whereExpression);
            }
          }
        }
      }
      return query.toString();
    }
 catch (    ParseException e) {
      log.warn("String_Node_Str" + statement + "String_Node_Str"+ e,e);
    }
  }
  if (statement.contains("String_Node_Str") && statement.contains("String_Node_Str")) {
    int insertIdx=statement.indexOf("String_Node_Str");
    StringBuilder finalQuery=new StringBuilder().append(statement.substring(0,insertIdx)).append(where()).append(surroundWithSpaces(whereClause)).append(statement.substring(insertIdx));
    return finalQuery.toString();
  }
  if (statement.contains(AND_WHERE_CLAUSE)) {
    whereClause=whereClause.length() != 0 ? and() + whereClause : whereClause;
    return statement.replaceAll(AND_WHERE_CLAUSE,whereClause);
  }
  String op=statement.toUpperCase().contains(where()) ? and() : where();
  String finalQuery=statement + op + whereClause;
  log.warn("String_Node_Str" + finalQuery);
  return finalQuery;
}