Program: 63353
Project: 63353
Buggy source:
static CubeInstance findBestMatchCube(ProjectManager projectManager,OLAPContext olapContext) throws CubeNotFoundException {
  String factTableName=olapContext.firstTableScan.getCubeTable();
  String projectName=olapContext.olapSchema.getProjectName();
  Collection<TblColRef> dimensionColumns=getDimensionColumns(olapContext);
  Collection<FunctionDesc> functions=olapContext.aggregations;
  Collection<TblColRef> metricsColumns=olapContext.metricsColumns;
  Collection<JoinDesc> joins=olapContext.joins;
  Map<String,RelDataType> rewriteFields=olapContext.rewriteFields;
  List<CubeInstance> candidates=projectManager.getCubesByTable(projectName,factTableName);
  StringBuilder buf=new StringBuilder();
  for (  CubeInstance cube : candidates) {
    buf.append(cube.getName());
    buf.append("String_Node_Str");
  }
  logger.info("String_Node_Str" + factTableName + "String_Node_Str"+ projectName+ "String_Node_Str"+ buf.toString());
  Iterator<CubeInstance> it=candidates.iterator();
  List<CubeInstance> backups=new ArrayList<CubeInstance>();
  while (it.hasNext()) {
    CubeInstance cube=it.next();
    boolean isOnline=cube.isReady();
    boolean matchDimensions=isMatchedWithDimensions(dimensionColumns,cube);
    boolean matchAggregation=isMatchedWithAggregations(functions,cube);
    boolean matchJoin=isMatchedWithJoins(joins,cube);
    if (isOnline && matchDimensions && !matchAggregation&& matchJoin) {
      if (isWeaklyMatchedWithAggregations(functions,metricsColumns,cube)) {
        logger.info("String_Node_Str" + cube);
        backups.add(cube);
      }
    }
    if (!isOnline || !matchDimensions || !matchAggregation|| !matchJoin) {
      logger.info("String_Node_Str" + cube.getName() + "String_Node_Str"+ "String_Node_Str"+ isOnline+ "String_Node_Str"+ matchDimensions+ "String_Node_Str"+ matchAggregation+ "String_Node_Str"+ matchJoin);
      it.remove();
    }
  }
  if (!candidates.isEmpty()) {
    return getCheapestCube(candidates);
  }
 else   if (!backups.isEmpty()) {
    CubeInstance cube=getCheapestCube(backups);
    adjustOLAPContext(dimensionColumns,functions,metricsColumns,cube,rewriteFields,olapContext);
    logger.info("String_Node_Str" + cube.getName());
    return cube;
  }
  return null;
}

Fixed version (ground truth):
static CubeInstance findBestMatchCube(ProjectManager projectManager,OLAPContext olapContext) throws CubeNotFoundException {
  String factTableName=olapContext.firstTableScan.getCubeTable();
  String projectName=olapContext.olapSchema.getProjectName();
  Collection<TblColRef> dimensionColumns=getDimensionColumns(olapContext);
  Collection<FunctionDesc> functions=olapContext.aggregations;
  Collection<TblColRef> metricsColumns=olapContext.metricsColumns;
  Collection<JoinDesc> joins=olapContext.joins;
  Map<String,RelDataType> rewriteFields=olapContext.rewriteFields;
  List<CubeInstance> candidates=projectManager.getCubesByTable(projectName,factTableName);
  logger.info("String_Node_Str" + factTableName + "String_Node_Str"+ projectName+ "String_Node_Str"+ StringUtils.join(candidates,"String_Node_Str"));
  Iterator<CubeInstance> it=candidates.iterator();
  List<CubeInstance> backups=new ArrayList<CubeInstance>();
  while (it.hasNext()) {
    CubeInstance cube=it.next();
    boolean isOnline=cube.isReady();
    boolean matchDimensions=isMatchedWithDimensions(dimensionColumns,cube);
    boolean matchAggregation=isMatchedWithAggregations(functions,cube);
    boolean matchJoin=isMatchedWithJoins(joins,cube);
    if (isOnline && matchDimensions && !matchAggregation&& matchJoin) {
      if (isWeaklyMatchedWithAggregations(functions,metricsColumns,cube)) {
        logger.info("String_Node_Str" + cube);
        backups.add(cube);
      }
    }
    if (!isOnline || !matchDimensions || !matchAggregation|| !matchJoin) {
      logger.info("String_Node_Str" + cube.getName() + "String_Node_Str"+ "String_Node_Str"+ isOnline+ "String_Node_Str"+ matchDimensions+ "String_Node_Str"+ matchAggregation+ "String_Node_Str"+ matchJoin);
      it.remove();
    }
  }
  if (!candidates.isEmpty()) {
    return getCheapestCube(candidates);
  }
 else   if (!backups.isEmpty()) {
    CubeInstance cube=getCheapestCube(backups);
    adjustOLAPContext(dimensionColumns,functions,metricsColumns,cube,rewriteFields,olapContext);
    logger.info("String_Node_Str" + cube.getName());
    return cube;
  }
  return null;
}