Program: 67006
Project: 67006
Buggy source:
/** 
 * Creates the cube query definition for chart. If parent definition is null, it's usually used for Live preview in chart builder. If chart in xtab, will return sub cube query definition.
 * @param parent
 * @param expressions the extended expressions.
 * @return ICubeQueryDefinition for cube consuming orISubCubeQueryDefinition for chart in xtab case
 * @throws BirtException
 * @since 2.5.2
 */
public IBaseCubeQueryDefinition createCubeQuery(IDataQueryDefinition parent,String[] expressions) throws BirtException {
  bSingleChart=parent == null;
  CubeHandle cubeHandle=getCubeHandle();
  ICubeQueryDefinition cubeQuery=null;
  if (cubeHandle == null) {
    cubeHandle=ChartCubeUtil.getBindingCube(handle);
    if (cubeHandle == null) {
      throw new ChartException(ChartReportItemConstants.ID,ChartException.NULL_DATASET,Messages.getString("String_Node_Str"));
    }
    if (parent instanceof ICubeQueryDefinition) {
      ISubCubeQueryDefinition subQuery=createSubCubeQuery();
      if (subQuery != null) {
        if (ChartCubeUtil.isPlotChart(handle)) {
          addMinMaxBinding((ICubeQueryDefinition)parent);
        }
        return subQuery;
      }
      Iterator<ComputedColumnHandle> bindings=handle.columnBindingsIterator();
      if (!bindings.hasNext()) {
        return (ICubeQueryDefinition)parent;
      }
    }
  }
  cubeQuery=getCubeElementFactory().createCubeQuery(cubeHandle.getQualifiedName());
  initBindings(cubeQuery,cubeHandle);
  List<SeriesDefinition> sdList=getAllSeriesDefinitions(cm);
  ExpressionSet exprSet=getExpressions(expressions,sdList);
  for (  String expr : exprSet) {
    bindExpression(expr,cubeQuery,cubeHandle);
  }
  for (int i=0; i < sdList.size(); i++) {
    SeriesDefinition sd=sdList.get(i);
    addSorting(cubeQuery,cubeHandle,sd,i);
  }
  addCubeFilter(cubeQuery,cubeHandle);
  sortLevelDefinition(cubeQuery.getEdge(ICubeQueryDefinition.ROW_EDGE),cubeHandle);
  sortLevelDefinition(cubeQuery.getEdge(ICubeQueryDefinition.COLUMN_EDGE),cubeHandle);
  Collection<ILevelDefinition> levelsInOrder=getAllLevelsInHierarchyOrder(cubeHandle,cubeQuery);
  addAggregateOnToMeasures(levelsInOrder);
  return cubeQuery;
}

Fixed version (ground truth):
/** 
 * Creates the cube query definition for chart. If parent definition is null, it's usually used for Live preview in chart builder. If chart in xtab, will return sub cube query definition.
 * @param parent
 * @param expressions the extended expressions.
 * @return ICubeQueryDefinition for cube consuming orISubCubeQueryDefinition for chart in xtab case
 * @throws BirtException
 * @since 2.5.2
 */
public IBaseCubeQueryDefinition createCubeQuery(IDataQueryDefinition parent,String[] expressions) throws BirtException {
  bSingleChart=parent == null;
  CubeHandle cubeHandle=getCubeHandle();
  ICubeQueryDefinition cubeQuery=null;
  if (cubeHandle == null) {
    cubeHandle=ChartCubeUtil.getBindingCube(handle);
    if (cubeHandle == null) {
      throw new ChartException(ChartReportItemConstants.ID,ChartException.NULL_DATASET,Messages.getString("String_Node_Str"));
    }
    if (parent instanceof ICubeQueryDefinition) {
      ISubCubeQueryDefinition subQuery=createSubCubeQuery();
      if (ChartCubeUtil.isPlotChart(handle)) {
        addMinMaxBinding((ICubeQueryDefinition)parent);
      }
      if (subQuery != null) {
        return subQuery;
      }
      Iterator<ComputedColumnHandle> bindings=handle.columnBindingsIterator();
      if (!bindings.hasNext()) {
        return (ICubeQueryDefinition)parent;
      }
    }
  }
  cubeQuery=getCubeElementFactory().createCubeQuery(cubeHandle.getQualifiedName());
  initBindings(cubeQuery,cubeHandle);
  List<SeriesDefinition> sdList=getAllSeriesDefinitions(cm);
  ExpressionSet exprSet=getExpressions(expressions,sdList);
  for (  String expr : exprSet) {
    bindExpression(expr,cubeQuery,cubeHandle);
  }
  for (int i=0; i < sdList.size(); i++) {
    SeriesDefinition sd=sdList.get(i);
    addSorting(cubeQuery,cubeHandle,sd,i);
  }
  addCubeFilter(cubeQuery,cubeHandle);
  sortLevelDefinition(cubeQuery.getEdge(ICubeQueryDefinition.ROW_EDGE),cubeHandle);
  sortLevelDefinition(cubeQuery.getEdge(ICubeQueryDefinition.COLUMN_EDGE),cubeHandle);
  Collection<ILevelDefinition> levelsInOrder=getAllLevelsInHierarchyOrder(cubeHandle,cubeQuery);
  addAggregateOnToMeasures(levelsInOrder);
  return cubeQuery;
}