Program: 65846
Project: 65846
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[] aggrDefns=prepareCube(executor.getCubeQueryDefinition(),view.getAggregationRegisterTable().getCalculatedMembersFromQuery());
  if (aggrDefns == null || aggrDefns.length == 0)   return null;
  DrilledAggregationDefinition[] drillAggrDefns=preparedDrillAggregation(executor.getCubeQueryDefinition(),aggrDefns);
  int size=aggrDefns.length + drillAggrDefns.length;
  AggregationDefinition[] finalAggregation=new AggregationDefinition[size];
  if (drillAggrDefns.length > 0) {
    System.arraycopy(aggrDefns,0,finalAggregation,0,aggrDefns.length);
    System.arraycopy(drillAggrDefns,0,finalAggregation,aggrDefns.length,drillAggrDefns.length);
  }
 else {
    finalAggregation=aggrDefns;
  }
  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.setMemoryCacheSize(CacheUtil.computeMemoryBufferSize(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(view,stopSign,rs,aggrDefns);
      break;
    }
case DataEngineContext.DIRECT_PRESENTATION:
{
    rs=populateRs(view,finalAggregation,cubeQueryExecutorHelper,stopSign,false,fetcher);
    rs=processOperationOnQuery(view,stopSign,rs,aggrDefns);
    break;
  }
case DataEngineContext.MODE_PRESENTATION:
{
  if (executor.getCubeQueryDefinition().getQueryResultsID() != null) {
    rs=AggregationResultSetSaveUtil.load(executor.getCubeQueryDefinition().getQueryResultsID(),executor.getContext().getDocReader(),new VersionManager(executor.getContext()).getVersion(),cubeQueryExecutorHelper.getMemoryCacheSize());
    initLoadedAggregationResultSets(rs,finalAggregation);
    rs=processOperationOnQuery(view,stopSign,rs,aggrDefns);
    break;
  }
 else {
    rs=cubeQueryExecutorHelper.execute(finalAggregation,stopSign);
    rs=applyNoAggrUpdateFilters(getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters()),executor,rs,cube,fetcher);
    MirrorOperationExecutor moe=new MirrorOperationExecutor();
    rs=moe.execute(rs,view,cubeQueryExecutorHelper);
    validateLimitSetting(view,rs);
    rs=processOperationOnQuery(view,stopSign,rs,aggrDefns);
    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() || (!ieh.isNoIncrement() && executor.getCubeQueryDefinition().getCubeOperations().length > 0)) {
  rs=cubeQueryExecutorHelper.execute(finalAggregation,stopSign);
  rs=applyNoAggrUpdateFilters(getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters()),executor,rs,cube,fetcher);
  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(),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);
  }
}
if (executor.getContext().getDocWriter() != null) {
  if (id == null) {
    id=executor.getSession().getQueryResultIDUtil().nextID();
  }
  CubeQueryDefinitionIOUtil.save(id,executor.getContext().getDocWriter(),executor.getCubeQueryDefinition());
  AggregationResultSetSaveUtil.save(id,rs,executor.getContext().getDocWriter());
  executor.setQueryResultsId(id);
}
rs=processOperationOnQuery(view,stopSign,rs,aggrDefns);
}
}
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[] aggrDefns=prepareCube(executor.getCubeQueryDefinition(),view.getAggregationRegisterTable().getCalculatedMembersFromQuery());
  if (aggrDefns == null || aggrDefns.length == 0)   return null;
  DrilledAggregationDefinition[] drillAggrDefns=preparedDrillAggregation(executor.getCubeQueryDefinition(),aggrDefns);
  int size=aggrDefns.length + drillAggrDefns.length;
  AggregationDefinition[] finalAggregation=new AggregationDefinition[size];
  if (drillAggrDefns.length > 0) {
    System.arraycopy(aggrDefns,0,finalAggregation,0,aggrDefns.length);
    System.arraycopy(drillAggrDefns,0,finalAggregation,aggrDefns.length,drillAggrDefns.length);
  }
 else {
    finalAggregation=aggrDefns;
  }
  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.setMemoryCacheSize(CacheUtil.computeMemoryBufferSize(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(view,stopSign,rs,aggrDefns);
      break;
    }
case DataEngineContext.DIRECT_PRESENTATION:
{
    rs=populateRs(view,finalAggregation,cubeQueryExecutorHelper,stopSign,false,fetcher);
    rs=processOperationOnQuery(view,stopSign,rs,aggrDefns);
    break;
  }
case DataEngineContext.MODE_PRESENTATION:
{
  if (executor.getCubeQueryDefinition().getQueryResultsID() != null) {
    rs=AggregationResultSetSaveUtil.load(executor.getCubeQueryDefinition().getQueryResultsID(),executor.getContext().getDocReader(),new VersionManager(executor.getContext()).getVersion(),cubeQueryExecutorHelper.getMemoryCacheSize());
    initLoadedAggregationResultSets(rs,finalAggregation);
    rs=processOperationOnQuery(view,stopSign,rs,aggrDefns);
    break;
  }
 else {
    rs=cubeQueryExecutorHelper.execute(finalAggregation,stopSign);
    rs=applyNoAggrUpdateFilters(getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters()),executor,rs,cube,fetcher);
    MirrorOperationExecutor moe=new MirrorOperationExecutor();
    rs=moe.execute(rs,view,cubeQueryExecutorHelper);
    validateLimitSetting(view,rs);
    rs=processOperationOnQuery(view,stopSign,rs,aggrDefns);
    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() || (!ieh.isNoIncrement() && executor.getCubeQueryDefinition().getCubeOperations().length > 0)) {
  rs=cubeQueryExecutorHelper.execute(finalAggregation,stopSign);
  rs=applyNoAggrUpdateFilters(getNoAggrUpdateFilters(executor.getCubeQueryDefinition().getFilters()),executor,rs,cube,fetcher);
  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(),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);
  }
}
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(view,stopSign,rs,aggrDefns);
}
}
return new CubeResultSet(rs,view,cubeQueryExecutorHelper);
}