Program: 69205
Project: 69205
Buggy source:
/** 
 * @param view
 * @param query
 * @param stopSign
 * @return
 * @throws IOException
 * @throws BirtException
 */
public IResultSet execute(BirtCubeView view,StopSign stopSign,ICube cube) throws IOException, BirtException {
  CubeQueryExecutor executor=view.getCubeQueryExecutor();
  AggregationDefinition[] aggrDefns=prepareCube(executor.getCubeQueryDefinition(),view.getAggregationRegisterTable().getCalculatedMembersFromQuery());
  if (aggrDefns == null || aggrDefns.length == 0)   return null;
  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());
  cubeQueryExecutorHelper.addJSFilter(executor.getDimensionFilterEvalHelpers());
  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,aggrDefns,cubeQueryExecutorHelper,stopSign,true);
      break;
    }
case DataEngineContext.DIRECT_PRESENTATION:
{
    rs=populateRs(view,aggrDefns,cubeQueryExecutorHelper,stopSign,false);
    break;
  }
case DataEngineContext.MODE_PRESENTATION:
{
  if (executor.getCubeQueryDefinition().getQueryResultsID() != null) {
    rs=AggregationResultSetSaveUtil.load(executor.getCubeQueryDefinition().getQueryResultsID(),executor.getContext().getDocReader(),new VersionManager(executor.getContext()).getVersion());
    break;
  }
 else {
    rs=cubeQueryExecutorHelper.execute(aggrDefns,stopSign);
    CubeOperationsExecutor coe=new CubeOperationsExecutor(view.getCubeQueryDefinition(),view.getPreparedCubeOperations(),view.getCubeQueryExecutor().getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext());
    rs=coe.execute(rs,stopSign);
    break;
  }
}
default :
{
rs=cubeQueryExecutorHelper.execute(aggrDefns,stopSign);
CubeOperationsExecutor coe=new CubeOperationsExecutor(view.getCubeQueryDefinition(),view.getPreparedCubeOperations(),view.getCubeQueryExecutor().getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext());
rs=coe.execute(rs,stopSign);
String id=executor.getCubeQueryDefinition().getQueryResultsID();
if (id == null) {
  id=executor.getSession().getQueryResultIDUtil().nextID();
}
AggregationResultSetSaveUtil.save(id,rs,executor.getContext().getDocWriter());
executor.setQueryResultsId(id);
}
}
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) throws IOException, BirtException {
  CubeQueryExecutor executor=view.getCubeQueryExecutor();
  AggregationDefinition[] aggrDefns=prepareCube(executor.getCubeQueryDefinition(),view.getAggregationRegisterTable().getCalculatedMembersFromQuery());
  if (aggrDefns == null || aggrDefns.length == 0)   return null;
  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());
  cubeQueryExecutorHelper.addJSFilter(executor.getDimensionFilterEvalHelpers());
  cubeQueryExecutorHelper.addAggrMeasureFilter(executor.getMeasureFilterEvalHelpers());
  cubeQueryExecutorHelper.addMeasureFilter(executor.getFacttableBasedFilterHelpers());
  if (view.getCubeQueryDefinition() instanceof DrillCubeQueryDefinition) {
    DrillCubeQueryDefinition query=(DrillCubeQueryDefinition)view.getCubeQueryDefinition();
    for (int i=0; i < query.getLevelFilter().size(); i++) {
      cubeQueryExecutorHelper.addFilter((LevelFilter)query.getLevelFilter().get(i));
    }
  }
  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,aggrDefns,cubeQueryExecutorHelper,stopSign,true);
      break;
    }
case DataEngineContext.DIRECT_PRESENTATION:
{
    rs=populateRs(view,aggrDefns,cubeQueryExecutorHelper,stopSign,false);
    break;
  }
case DataEngineContext.MODE_PRESENTATION:
{
  if (executor.getCubeQueryDefinition().getQueryResultsID() != null) {
    rs=AggregationResultSetSaveUtil.load(executor.getCubeQueryDefinition().getQueryResultsID(),executor.getContext().getDocReader(),new VersionManager(executor.getContext()).getVersion());
    break;
  }
 else {
    rs=cubeQueryExecutorHelper.execute(aggrDefns,stopSign);
    CubeOperationsExecutor coe=new CubeOperationsExecutor(view.getCubeQueryDefinition(),view.getPreparedCubeOperations(),view.getCubeQueryExecutor().getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext());
    rs=coe.execute(rs,stopSign);
    break;
  }
}
default :
{
rs=cubeQueryExecutorHelper.execute(aggrDefns,stopSign);
CubeOperationsExecutor coe=new CubeOperationsExecutor(view.getCubeQueryDefinition(),view.getPreparedCubeOperations(),view.getCubeQueryExecutor().getScope(),view.getCubeQueryExecutor().getSession().getEngineContext().getScriptContext());
rs=coe.execute(rs,stopSign);
String id=executor.getCubeQueryDefinition().getQueryResultsID();
if (id == null) {
  id=executor.getSession().getQueryResultIDUtil().nextID();
}
AggregationResultSetSaveUtil.save(id,rs,executor.getContext().getDocWriter());
executor.setQueryResultsId(id);
}
}
return new CubeResultSet(rs,view,cubeQueryExecutorHelper);
}