Program: 72160
Project: 72160
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
 * @return ICubeQueryDefinition for cube consuming orISubCubeQueryDefinition for chart in xtab case
 * @throws BirtException
 */
public IBaseCubeQueryDefinition createCubeQuery(IDataQueryDefinition parent) throws BirtException {
  bSingleChart=parent == null;
  CubeHandle cubeHandle=handle.getCube();
  ICubeQueryDefinition cubeQuery=null;
  if (cubeHandle == null) {
    cubeHandle=ChartXTabUtil.getBindingCube(handle);
    if (cubeHandle == null) {
      throw new ChartException(ChartReportItemPlugin.ID,ChartException.NULL_DATASET,Messages.getString("String_Node_Str"));
    }
    if (!bSingleChart) {
      ISubCubeQueryDefinition subQuery=createSubCubeQuery();
      if (subQuery != null) {
        if (parent instanceof ICubeQueryDefinition) {
          addMinMaxBinding((ICubeQueryDefinition)parent);
        }
        return subQuery;
      }
    }
  }
  cubeQuery=ChartXTabUtil.getCubeElementFactory().createCubeQuery(cubeHandle.getQualifiedName());
  initBindings(cubeQuery,cubeHandle);
  List<SeriesDefinition> sdList=getAllSeriesDefinitions(cm);
  for (int i=0; i < sdList.size(); i++) {
    SeriesDefinition sd=sdList.get(i);
    List<Query> queryList=sd.getDesignTimeSeries().getDataDefinition();
    for (int j=0; j < queryList.size(); j++) {
      Query query=queryList.get(j);
      bindSeriesQuery(query.getDefinition(),cubeQuery,cubeHandle);
    }
    bindSeriesQuery(sd.getQuery().getDefinition(),cubeQuery,cubeHandle);
  }
  Collection<ILevelDefinition> levelsInOrder=getAllLevelsInHierarchyOrder(cubeHandle,cubeQuery);
  for (Iterator<String> measureNames=registeredMeasures.keySet().iterator(); measureNames.hasNext(); ) {
    Binding binding=registeredBindings.get(measureNames.next());
    if (binding != null && binding.getAggregatOns().isEmpty()) {
      for (Iterator<ILevelDefinition> levels=levelsInOrder.iterator(); levels.hasNext(); ) {
        ILevelDefinition level=levels.next();
        String dimensionName=level.getHierarchy().getDimension().getName();
        binding.addAggregateOn(ExpressionUtil.createJSDimensionExpression(dimensionName,level.getName()));
      }
    }
  }
  for (int i=0; i < sdList.size(); i++) {
    SeriesDefinition sd=(SeriesDefinition)sdList.get(i);
    addSorting(cubeQuery,cubeHandle,sd,i);
  }
  addCubeFilter(cubeQuery);
  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
 * @return ICubeQueryDefinition for cube consuming orISubCubeQueryDefinition for chart in xtab case
 * @throws BirtException
 */
public IBaseCubeQueryDefinition createCubeQuery(IDataQueryDefinition parent) throws BirtException {
  bSingleChart=parent == null;
  CubeHandle cubeHandle=handle.getCube();
  ICubeQueryDefinition cubeQuery=null;
  if (cubeHandle == null) {
    cubeHandle=ChartXTabUtil.getBindingCube(handle);
    if (cubeHandle == null) {
      throw new ChartException(ChartReportItemPlugin.ID,ChartException.NULL_DATASET,Messages.getString("String_Node_Str"));
    }
    if (!bSingleChart) {
      ISubCubeQueryDefinition subQuery=createSubCubeQuery();
      if (subQuery != null) {
        if (parent instanceof ICubeQueryDefinition) {
          addMinMaxBinding((ICubeQueryDefinition)parent);
        }
        return subQuery;
      }
    }
  }
  cubeQuery=ChartXTabUtil.getCubeElementFactory().createCubeQuery(cubeHandle.getQualifiedName());
  initBindings(cubeQuery,cubeHandle);
  List<SeriesDefinition> sdList=getAllSeriesDefinitions(cm);
  for (int i=0; i < sdList.size(); i++) {
    SeriesDefinition sd=sdList.get(i);
    List<Query> queryList=sd.getDesignTimeSeries().getDataDefinition();
    for (int j=0; j < queryList.size(); j++) {
      Query query=queryList.get(j);
      bindSeriesQuery(query.getDefinition(),cubeQuery,cubeHandle);
    }
    bindSeriesQuery(sd.getQuery().getDefinition(),cubeQuery,cubeHandle);
  }
  Collection<ILevelDefinition> levelsInOrder=getAllLevelsInHierarchyOrder(cubeHandle,cubeQuery);
  for (Iterator<String> measureNames=registeredMeasures.keySet().iterator(); measureNames.hasNext(); ) {
    IBinding binding=registeredBindings.get(measureNames.next());
    if (binding != null && binding.getAggregatOns().isEmpty()) {
      for (Iterator<ILevelDefinition> levels=levelsInOrder.iterator(); levels.hasNext(); ) {
        ILevelDefinition level=levels.next();
        String dimensionName=level.getHierarchy().getDimension().getName();
        binding.addAggregateOn(ExpressionUtil.createJSDimensionExpression(dimensionName,level.getName()));
      }
    }
  }
  for (int i=0; i < sdList.size(); i++) {
    SeriesDefinition sd=(SeriesDefinition)sdList.get(i);
    addSorting(cubeQuery,cubeHandle,sd,i);
  }
  addCubeFilter(cubeQuery);
  return cubeQuery;
}