Program: 140237
Project: 140237
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)) {
          ZqlParser filterParser=getZqlParser();
          filterParser.initParser(new ByteArrayInputStream(whereClause.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();
  }
  String op=statement.toUpperCase().contains(where()) ? and() : where();
  String finalQuery=statement + op + whereClause;
  log.warn("String_Node_Str" + finalQuery);
  return finalQuery;
}