Program: 65545
Project: 65545
Buggy source:
/** 
 * @param view
 * @param query
 * @param stopSign
 * @return
 * @throws IOException
 * @throws BirtException
 */
public IResultSet execute(BirtCubeView view,StopSign stopSign,ICube cube,IBindingValueFetcher fetcher) throws IOException, BirtException {
  CubeQueryExecutor executor=view.getCubeQueryExecutor();
  AggregationDefinition[] cube_Aggregation=prepareCube(executor.getCubeQueryDefinition(),view.getAggregationRegisterTable().getCalculatedMembersFromQuery());
  if (cube_Aggregation == null || cube_Aggregation.length == 0)   return null;
  AggregationDefinition[] drilled_aggregation=DrillFilterHelper.preparedDrillAggregation(executor.getCubeQueryDefinition(),cube_Aggregation);
  int size=cube_Aggregation.length + drilled_aggregation.length;
  AggregationDefinition[] finalAggregation=new AggregationDefinition[size];
  if (drilled_aggregation.length > 0) {
    System.arraycopy(cube_Aggregation,0,finalAggregation,0,cube_Aggregation.length);
    System.arraycopy(drilled_aggregation,0,finalAggregation,cube_Aggregation.length,drilled_aggregation.length);
  }
 else {
    finalAggregation=cube_Aggregation;
  }
  String cubeName=executor.getCubeQueryDefinition().getName();
  if (cubeName == null || cubeName.trim().length() == 0) {
    throw new DataException(ResourceConstants.CUBE_QUERY_NO_CUBE_BINDING);
  }
  CubeQueryValidator.validateCubeQueryDefinition(view,cube);
  cubeQueryExecutorHelper=new CubeQueryExecutorHelper(cube,executor.getComputedMeasureHelper(),fetcher);
  cubeQueryExecutorHelper.setCubeQueryExecutor(executor);
  cubeQueryExecutorHelper.setMemoryCacheSize(CacheUtil.computeMemoryBufferSize(view.getAppContext()));
  cubeQueryExecutorHelper.setAppContext(view.getAppContext());
  cubeQueryExecutorHelper.setMaxDataObjectRows(CacheUtil.getMaxRows(view.getAppContext()));
  cubeQueryExecutorHelper.addJSFilter(executor.getDimensionFilterEvalHelpers());
  cubeQueryExecutorHelper.addSimpleLevelFilter(executor.getdimensionSimpleFilter());
  cubeQueryExecutorHelper.addAggrMeasureFilter(executor.getMeasureFilterEvalHelpers());
  cubeQueryExecutorHelper.addMeasureFilter(executor.getFacttableBasedFilterHelpers());
  populateAggregationSort(executor,cubeQueryExecutorHelper,ICubeQueryDefinition.COLUMN_EDGE);
  populateAggregationSort(executor,cubeQueryExecutorHelper,ICubeQueryDefinition.ROW_EDGE);
  populateAggregationSort(executor,cubeQueryExecutorHelper,ICubeQueryDefinition.PAGE_EDGE);
  IAggregationResultSet[] rs=null;
  cubeQueryExecutorHelper.setBreakHierarchy(executor.getCubeQueryDefinition().getFilterOption() == 0);
switch (executor.getContext().getMode()) {
case DataEngineContext.MODE_GENERATION:
{
      rs=populateRs(view,finalAggregation,cubeQueryExecutorHelper,stopSign,true,fetcher);
      rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
      break;
    }
case DataEngineContext.DIRECT_PRESENTATION:
{
    rs=populateRs(view,finalAggregation,cubeQueryExecutorHelper,stopSign,false,fetcher);
    rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
    break;
  }
case DataEngineContext.MODE_PRESENTATION:
{
  if (executor.getCubeQueryDefinition().getQueryResultsID() != null) {
    rs=AggregationResultSetSaveUtil.load(executor.getCubeQueryDefinition().getQueryResultsID(),executor.getContext().getDocReader(),new VersionManager(executor.getContext()).getVersion(executor.getCubeQueryDefinition().getQueryResultsID()),cubeQueryExecutorHelper.getMemoryCacheSize());
    initLoadedAggregationResultSets(rs,finalAggregation);
    rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
    break;
  }
 else {
    rs=cubeQueryExecutorHelper.execute(finalAggregation,stopSign);
    rs=applyNoAggrUpdateFilters(getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters()),executor,rs,cube,fetcher,false);
    MirrorOperationExecutor moe=new MirrorOperationExecutor();
    rs=moe.execute(rs,view,cubeQueryExecutorHelper);
    validateLimitSetting(view,rs);
    rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
    break;
  }
}
default :
{
String id=executor.getCubeQueryDefinition().getQueryResultsID();
IncrementExecutionHint ieh=null;
if (CubeQueryDefinitionIOUtil.existStream(executor.getContext().getDocReader(),id)) {
  ICubeQueryDefinition savedQuery=CubeQueryDefinitionIOUtil.load(id,executor.getContext());
  ieh=org.eclipse.birt.data.engine.olap.impl.query.CubeQueryDefinitionUtil.getIncrementExecutionHint(savedQuery,executor.getCubeQueryDefinition());
}
if (!CubeQueryDefinitionIOUtil.existStream(executor.getContext().getDocReader(),id) || ieh == null || (!ieh.isNoIncrement() && executor.getCubeQueryDefinition().getCubeOperations().length > 0)) {
  rs=cubeQueryExecutorHelper.execute(finalAggregation,stopSign);
  rs=applyNoAggrUpdateFilters(getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters()),executor,rs,cube,fetcher,false);
  MirrorOperationExecutor moe=new MirrorOperationExecutor();
  rs=moe.execute(rs,view,cubeQueryExecutorHelper);
  this.validateLimitSetting(view,rs);
}
 else {
  rs=AggregationResultSetSaveUtil.load(id,executor.getContext().getDocReader(),new VersionManager(executor.getContext()).getVersion(id),cubeQueryExecutorHelper.getMemoryCacheSize());
  initLoadedAggregationResultSets(rs,finalAggregation);
  incrementExecute(rs,ieh);
  if (ieh.getFilters() != null && ieh.getFilters().length > 0) {
    IFilterDefinition[] filters=ieh.getFilters();
    List finalFilters=new ArrayList();
    for (int j=0; j < filters.length; j++) {
      finalFilters.add(filters[j]);
    }
    rs=applyNoAggrUpdateFilters(finalFilters,executor,rs,cube,fetcher,false);
  }
}
if (executor.getContext().getDocWriter() != null) {
  if (id == null) {
    id=executor.getSession().getQueryResultIDUtil().nextID();
  }
  CubeQueryDefinitionIOUtil.save(id,executor.getContext(),executor.getCubeQueryDefinition());
  AggregationResultSetSaveUtil.save(id,rs,executor.getContext().getDocWriter());
  executor.setQueryResultsId(id);
}
rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
}
}
return new CubeResultSet(rs,view,cubeQueryExecutorHelper);
}

Fixed version (ground truth):
/** 
 * @param view
 * @param query
 * @param stopSign
 * @return
 * @throws IOException
 * @throws BirtException
 */
public IResultSet execute(BirtCubeView view,StopSign stopSign,ICube cube,IBindingValueFetcher fetcher) throws IOException, BirtException {
  CubeQueryExecutor executor=view.getCubeQueryExecutor();
  AggregationDefinition[] cube_Aggregation=prepareCube(executor.getCubeQueryDefinition(),view.getAggregationRegisterTable().getCalculatedMembersFromQuery());
  if (cube_Aggregation == null || cube_Aggregation.length == 0)   return null;
  AggregationDefinition[] drilled_aggregation=DrillFilterHelper.preparedDrillAggregation(executor.getCubeQueryDefinition(),cube_Aggregation);
  int size=cube_Aggregation.length + drilled_aggregation.length;
  AggregationDefinition[] finalAggregation=new AggregationDefinition[size];
  if (drilled_aggregation.length > 0) {
    System.arraycopy(cube_Aggregation,0,finalAggregation,0,cube_Aggregation.length);
    System.arraycopy(drilled_aggregation,0,finalAggregation,cube_Aggregation.length,drilled_aggregation.length);
  }
 else {
    finalAggregation=cube_Aggregation;
  }
  String cubeName=executor.getCubeQueryDefinition().getName();
  if (cubeName == null || cubeName.trim().length() == 0) {
    throw new DataException(ResourceConstants.CUBE_QUERY_NO_CUBE_BINDING);
  }
  CubeQueryValidator.validateCubeQueryDefinition(view,cube);
  cubeQueryExecutorHelper=new CubeQueryExecutorHelper(cube,executor.getComputedMeasureHelper(),fetcher);
  cubeQueryExecutorHelper.setCubeQueryExecutor(executor);
  cubeQueryExecutorHelper.setMemoryCacheSize(CacheUtil.computeMemoryBufferSize(view.getAppContext()));
  cubeQueryExecutorHelper.setAppContext(view.getAppContext());
  cubeQueryExecutorHelper.setMaxDataObjectRows(CacheUtil.getMaxRows(view.getAppContext()));
  cubeQueryExecutorHelper.addJSFilter(executor.getDimensionFilterEvalHelpers());
  cubeQueryExecutorHelper.addSimpleLevelFilter(executor.getdimensionSimpleFilter());
  cubeQueryExecutorHelper.addAggrMeasureFilter(executor.getMeasureFilterEvalHelpers());
  cubeQueryExecutorHelper.addMeasureFilter(executor.getFacttableBasedFilterHelpers());
  populateAggregationSort(executor,cubeQueryExecutorHelper,ICubeQueryDefinition.COLUMN_EDGE);
  populateAggregationSort(executor,cubeQueryExecutorHelper,ICubeQueryDefinition.ROW_EDGE);
  populateAggregationSort(executor,cubeQueryExecutorHelper,ICubeQueryDefinition.PAGE_EDGE);
  IAggregationResultSet[] rs=null;
  cubeQueryExecutorHelper.setBreakHierarchy(executor.getCubeQueryDefinition().getFilterOption() == 0);
switch (executor.getContext().getMode()) {
case DataEngineContext.MODE_GENERATION:
{
      rs=populateRs(view,finalAggregation,cubeQueryExecutorHelper,stopSign,true,fetcher);
      rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
      break;
    }
case DataEngineContext.DIRECT_PRESENTATION:
{
    rs=populateRs(view,finalAggregation,cubeQueryExecutorHelper,stopSign,false,fetcher);
    rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
    break;
  }
case DataEngineContext.MODE_PRESENTATION:
{
  if (executor.getCubeQueryDefinition().getQueryResultsID() != null) {
    rs=AggregationResultSetSaveUtil.load(executor.getCubeQueryDefinition().getQueryResultsID(),executor.getContext().getDocReader(),new VersionManager(executor.getContext()).getVersion(executor.getCubeQueryDefinition().getQueryResultsID()),cubeQueryExecutorHelper.getMemoryCacheSize());
    initLoadedAggregationResultSets(rs,finalAggregation);
    rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
    break;
  }
 else {
    rs=cubeQueryExecutorHelper.execute(finalAggregation,stopSign);
    rs=applyFilterOnOperation(view,stopSign,executor,finalAggregation,rs);
    rs=applyNoAggrUpdateFilters(getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters()),executor,rs,cube,fetcher,false);
    MirrorOperationExecutor moe=new MirrorOperationExecutor();
    rs=moe.execute(rs,view,cubeQueryExecutorHelper);
    validateLimitSetting(view,rs);
    rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
    break;
  }
}
default :
{
String id=executor.getCubeQueryDefinition().getQueryResultsID();
IncrementExecutionHint ieh=null;
if (CubeQueryDefinitionIOUtil.existStream(executor.getContext().getDocReader(),id)) {
  ICubeQueryDefinition savedQuery=CubeQueryDefinitionIOUtil.load(id,executor.getContext());
  ieh=org.eclipse.birt.data.engine.olap.impl.query.CubeQueryDefinitionUtil.getIncrementExecutionHint(savedQuery,executor.getCubeQueryDefinition());
}
if (!CubeQueryDefinitionIOUtil.existStream(executor.getContext().getDocReader(),id) || ieh == null || (!ieh.isNoIncrement() && executor.getCubeQueryDefinition().getCubeOperations().length > 0)) {
  rs=cubeQueryExecutorHelper.execute(finalAggregation,stopSign);
  rs=applyFilterOnOperation(view,stopSign,executor,finalAggregation,rs);
  rs=applyNoAggrUpdateFilters(getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters()),executor,rs,cube,fetcher,false);
  MirrorOperationExecutor moe=new MirrorOperationExecutor();
  rs=moe.execute(rs,view,cubeQueryExecutorHelper);
  this.validateLimitSetting(view,rs);
}
 else {
  rs=AggregationResultSetSaveUtil.load(id,executor.getContext().getDocReader(),new VersionManager(executor.getContext()).getVersion(id),cubeQueryExecutorHelper.getMemoryCacheSize());
  initLoadedAggregationResultSets(rs,finalAggregation);
  incrementExecute(rs,ieh);
  if (ieh.getFilters() != null && ieh.getFilters().length > 0) {
    IFilterDefinition[] filters=ieh.getFilters();
    List finalFilters=new ArrayList();
    for (int j=0; j < filters.length; j++) {
      finalFilters.add(filters[j]);
    }
    rs=applyNoAggrUpdateFilters(finalFilters,executor,rs,cube,fetcher,false);
  }
}
if (executor.getContext().getDocWriter() != null) {
  if (id == null) {
    id=executor.getSession().getQueryResultIDUtil().nextID();
  }
  CubeQueryDefinitionIOUtil.save(id,executor.getContext(),executor.getCubeQueryDefinition());
  AggregationResultSetSaveUtil.save(id,rs,executor.getContext().getDocWriter());
  executor.setQueryResultsId(id);
}
rs=processOperationOnQuery(executor,view,stopSign,rs,cube_Aggregation,fetcher);
}
}
return new CubeResultSet(rs,view,cubeQueryExecutorHelper);
}