Program: 68736
Project: 68736
Buggy source:
public static ICubeQueryDefinition createCubeQuery(CrosstabReportItemHandle crosstabItem,IDataQueryDefinition parentQuery,boolean needMeasure,boolean needRowDimension,boolean needColumnDimension,boolean needBinding,boolean needSorting,boolean needFilter) throws BirtException {
  ICubeQueryDefinition cubeQuery=getCubeElementFactory().createCubeQuery(crosstabItem.getCubeName());
  List<String> rowLevelNameList=new ArrayList<String>();
  List<String> columnLevelNameList=new ArrayList<String>();
  List<LevelViewHandle> levelViewList=new ArrayList<LevelViewHandle>();
  Map<LevelHandle,ILevelDefinition> levelMapping=new HashMap<LevelHandle,ILevelDefinition>();
  if (needMeasure) {
    for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
      MeasureViewHandle mv=crosstabItem.getMeasure(i);
      if (mv instanceof ComputedMeasureViewHandle) {
        continue;
      }
      if (mv.getCubeMeasure() == null) {
        throw new CrosstabException(Messages.getString("String_Node_Str",mv.getCubeMeasureName()));
      }
      IMeasureDefinition mDef=cubeQuery.createMeasure(mv.getCubeMeasure().getName());
      mDef.setAggrFunction(mv.getCubeMeasure().getFunction() == null ? null : DataAdapterUtil.getRollUpAggregationName(mv.getCubeMeasure().getFunction()));
      addFactTableOrMeasureFilter(mv.filtersIterator(),cubeQuery);
    }
  }
  if (needRowDimension && crosstabItem.getDimensionCount(ROW_AXIS_TYPE) > 0) {
    addEdgeDefinition(cubeQuery,crosstabItem,ROW_AXIS_TYPE,rowLevelNameList,levelViewList,levelMapping);
  }
  if (needColumnDimension && crosstabItem.getDimensionCount(COLUMN_AXIS_TYPE) > 0) {
    addEdgeDefinition(cubeQuery,crosstabItem,COLUMN_AXIS_TYPE,columnLevelNameList,levelViewList,levelMapping);
  }
  addFactTableOrMeasureFilter(crosstabItem.filtersIterator(),cubeQuery);
  if (needSorting) {
    addLevelSorting(levelViewList,levelMapping,cubeQuery);
  }
  if (needFilter) {
    addLevelFilter(levelViewList,levelMapping,cubeQuery);
  }
  if (needBinding) {
    Iterator bindingItr=((ExtendedItemHandle)crosstabItem.getModelHandle()).columnBindingsIterator();
    ModuleHandle module=((ExtendedItemHandle)crosstabItem.getModelHandle()).getModuleHandle();
    if (bindingItr != null) {
      Map<String,String> cache=new HashMap<String,String>();
      while (bindingItr.hasNext()) {
        ComputedColumnHandle column=(ComputedColumnHandle)bindingItr.next();
        Binding binding=new Binding(column.getName());
        binding.setAggrFunction(column.getAggregateFunction() == null ? null : DataAdapterUtil.adaptModelAggregationType(column.getAggregateFunction()));
        binding.setExpression(column.getExpression() == null ? null : new ScriptExpression(column.getExpression()));
        binding.setDataType(DataAdapterUtil.adaptModelDataType(column.getDataType()));
        if (column.getFilterExpression() != null) {
          binding.setFilter(new ScriptExpression(column.getFilterExpression()));
        }
        for (Iterator argItr=column.argumentsIterator(); argItr.hasNext(); ) {
          AggregationArgumentHandle aah=(AggregationArgumentHandle)argItr.next();
          if (aah.getValue() != null) {
            binding.addArgument(new ScriptExpression(aah.getValue()));
          }
        }
        List aggrList=column.getAggregateOnList();
        if (aggrList != null) {
          for (Iterator aggrItr=aggrList.iterator(); aggrItr.hasNext(); ) {
            String baseLevel=(String)aggrItr.next();
            CrosstabUtil.addHierachyAggregateOn(module,binding,baseLevel,rowLevelNameList,columnLevelNameList,cache);
          }
        }
        cubeQuery.addBinding(binding);
      }
    }
  }
  return cubeQuery;
}

Fixed version (ground truth):
public static ICubeQueryDefinition createCubeQuery(CrosstabReportItemHandle crosstabItem,IDataQueryDefinition parentQuery,boolean needMeasure,boolean needRowDimension,boolean needColumnDimension,boolean needBinding,boolean needSorting,boolean needFilter) throws BirtException {
  ICubeQueryDefinition cubeQuery=getCubeElementFactory().createCubeQuery(crosstabItem.getCubeName());
  List<String> rowLevelNameList=new ArrayList<String>();
  List<String> columnLevelNameList=new ArrayList<String>();
  List<LevelViewHandle> levelViewList=new ArrayList<LevelViewHandle>();
  Map<LevelHandle,ILevelDefinition> levelMapping=new HashMap<LevelHandle,ILevelDefinition>();
  DataRequestSession session=DataRequestSession.newSession(new DataSessionContext(DataSessionContext.MODE_DIRECT_PRESENTATION));
  try {
    IModelAdapter modelAdapter=session.getModelAdaptor();
    if (needMeasure) {
      for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
        MeasureViewHandle mv=crosstabItem.getMeasure(i);
        if (mv instanceof ComputedMeasureViewHandle) {
          continue;
        }
        if (mv.getCubeMeasure() == null) {
          throw new CrosstabException(Messages.getString("String_Node_Str",mv.getCubeMeasureName()));
        }
        IMeasureDefinition mDef=cubeQuery.createMeasure(mv.getCubeMeasure().getName());
        mDef.setAggrFunction(mv.getCubeMeasure().getFunction() == null ? null : DataAdapterUtil.getRollUpAggregationName(mv.getCubeMeasure().getFunction()));
        addFactTableOrMeasureFilter(mv.filtersIterator(),cubeQuery,modelAdapter);
      }
    }
    if (needRowDimension && crosstabItem.getDimensionCount(ROW_AXIS_TYPE) > 0) {
      addEdgeDefinition(cubeQuery,crosstabItem,ROW_AXIS_TYPE,rowLevelNameList,levelViewList,levelMapping);
    }
    if (needColumnDimension && crosstabItem.getDimensionCount(COLUMN_AXIS_TYPE) > 0) {
      addEdgeDefinition(cubeQuery,crosstabItem,COLUMN_AXIS_TYPE,columnLevelNameList,levelViewList,levelMapping);
    }
    addFactTableOrMeasureFilter(crosstabItem.filtersIterator(),cubeQuery,modelAdapter);
    if (needSorting) {
      addLevelSorting(levelViewList,levelMapping,cubeQuery,modelAdapter);
    }
    if (needFilter) {
      addLevelFilter(levelViewList,levelMapping,cubeQuery,modelAdapter);
    }
    if (needBinding) {
      Iterator bindingItr=((ExtendedItemHandle)crosstabItem.getModelHandle()).columnBindingsIterator();
      ModuleHandle module=((ExtendedItemHandle)crosstabItem.getModelHandle()).getModuleHandle();
      if (bindingItr != null) {
        Map<String,String> cache=new HashMap<String,String>();
        while (bindingItr.hasNext()) {
          ComputedColumnHandle column=(ComputedColumnHandle)bindingItr.next();
          Binding binding=new Binding(column.getName());
          binding.setAggrFunction(column.getAggregateFunction() == null ? null : DataAdapterUtil.adaptModelAggregationType(column.getAggregateFunction()));
          binding.setExpression(modelAdapter.adaptExpression((Expression)column.getExpressionProperty(ComputedColumn.EXPRESSION_MEMBER).getValue()));
          binding.setDataType(DataAdapterUtil.adaptModelDataType(column.getDataType()));
          if (column.getFilterExpression() != null) {
            binding.setFilter(modelAdapter.adaptExpression((Expression)column.getExpressionProperty(ComputedColumn.FILTER_MEMBER).getValue()));
          }
          for (Iterator argItr=column.argumentsIterator(); argItr.hasNext(); ) {
            AggregationArgumentHandle aah=(AggregationArgumentHandle)argItr.next();
            if (aah.getValue() != null) {
              binding.addArgument(modelAdapter.adaptExpression((Expression)aah.getExpressionProperty(AggregationArgument.VALUE_MEMBER).getValue()));
            }
          }
          List aggrList=column.getAggregateOnList();
          if (aggrList != null) {
            for (Iterator aggrItr=aggrList.iterator(); aggrItr.hasNext(); ) {
              String baseLevel=(String)aggrItr.next();
              CrosstabUtil.addHierachyAggregateOn(module,binding,baseLevel,rowLevelNameList,columnLevelNameList,cache);
            }
          }
          cubeQuery.addBinding(binding);
        }
      }
    }
  }
  finally {
    session.shutdown();
  }
  return cubeQuery;
}