Program: 24828
Project: 24828
Buggy source:
/** 
 * Simplify a BooleanQuery that contains other BooleanQuery/ies with the same type of clauses. If there's any boosting involved, don't do the optimization.
 */
private Query simplifyBooleanQuery(BooleanQuery bq){
  boolean anyBoosting=false;
  boolean anyBoolSubs=false;
  boolean allSame=true;
  boolean first=true;
  boolean prevRequired=true;
  boolean prevProhibited=true;
  BooleanClause[] clauses=bq.getClauses();
  for (int i=0; i < clauses.length; i++) {
    if (!first && (prevRequired != clauses[i].required || prevProhibited != clauses[i].prohibited))     allSame=false;
    prevRequired=clauses[i].required;
    prevProhibited=clauses[i].prohibited;
    first=false;
    if (clauses[i].query.getBoost() != 1.0f)     anyBoosting=true;
    if (clauses[i].query instanceof BooleanQuery) {
      BooleanQuery subQuery=(BooleanQuery)clauses[i].query;
      BooleanClause[] subClauses=subQuery.getClauses();
      for (int j=0; j < subClauses.length; j++) {
        if (prevRequired != subClauses[j].required || prevProhibited != subClauses[j].prohibited)         allSame=false;
        prevRequired=subClauses[j].required;
        prevProhibited=subClauses[j].prohibited;
        if (clauses[j].query.getBoost() != 1.0f)         anyBoosting=true;
      }
      anyBoolSubs=true;
    }
  }
  if (!anyBoolSubs || !allSame || anyBoosting)   return bq;
  bq=new BooleanQuery();
  for (int i=0; i < clauses.length; i++) {
    if (clauses[i].query instanceof BooleanQuery) {
      BooleanQuery subQuery=(BooleanQuery)clauses[i].query;
      BooleanClause[] subClauses=subQuery.getClauses();
      for (int j=0; j < subClauses.length; j++)       bq.add(subClauses[j]);
    }
 else     bq.add(clauses[i]);
  }
  return bq;
}

Fixed version (ground truth):
/** 
 * Simplify a BooleanQuery that contains other BooleanQuery/ies with the same type of clauses. If there's any boosting involved, don't do the optimization.
 */
private Query simplifyBooleanQuery(BooleanQuery bq){
  boolean anyBoosting=false;
  boolean anyBoolSubs=false;
  boolean allSame=true;
  boolean first=true;
  boolean prevRequired=true;
  boolean prevProhibited=true;
  BooleanClause[] clauses=bq.getClauses();
  for (int i=0; i < clauses.length; i++) {
    if (!first && (prevRequired != clauses[i].required || prevProhibited != clauses[i].prohibited))     allSame=false;
    prevRequired=clauses[i].required;
    prevProhibited=clauses[i].prohibited;
    first=false;
    if (clauses[i].query.getBoost() != 1.0f)     anyBoosting=true;
    if (clauses[i].query instanceof BooleanQuery) {
      BooleanQuery subQuery=(BooleanQuery)clauses[i].query;
      BooleanClause[] subClauses=subQuery.getClauses();
      for (int j=0; j < subClauses.length; j++) {
        if (prevRequired != subClauses[j].required || prevProhibited != subClauses[j].prohibited)         allSame=false;
        prevRequired=subClauses[j].required;
        prevProhibited=subClauses[j].prohibited;
        if (subClauses[j].query.getBoost() != 1.0f)         anyBoosting=true;
      }
      anyBoolSubs=true;
    }
  }
  if (!anyBoolSubs || !allSame || anyBoosting)   return bq;
  bq=new BooleanQuery();
  for (int i=0; i < clauses.length; i++) {
    if (clauses[i].query instanceof BooleanQuery) {
      BooleanQuery subQuery=(BooleanQuery)clauses[i].query;
      BooleanClause[] subClauses=subQuery.getClauses();
      for (int j=0; j < subClauses.length; j++)       bq.add(subClauses[j]);
    }
 else     bq.add(clauses[i]);
  }
  return bq;
}