Program: 73232
Project: 73232
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 {
  bLivePreview=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 (!bLivePreview) {
      ISubCubeQueryDefinition subQuery=createSubCubeQuery();
      if (subQuery != null) {
        return subQuery;
      }
    }
  }
  cubeQuery=ChartXTabUtil.getCubeElementFactory().createCubeQuery(cubeHandle.getQualifiedName());
  initBindings(cubeQuery,cubeHandle);
  List sdList=getAllSeriesDefinitions(cm);
  for (int i=0; i < sdList.size(); i++) {
    SeriesDefinition sd=(SeriesDefinition)sdList.get(i);
    List queryList=sd.getDesignTimeSeries().getDataDefinition();
    for (int j=0; j < queryList.size(); j++) {
      Query query=(Query)queryList.get(j);
      bindSeriesQuery(query,cubeQuery,cubeHandle);
    }
    bindSeriesQuery(sd.getQuery(),cubeQuery,cubeHandle);
  }
  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 {
  bLivePreview=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 (!bLivePreview) {
      ISubCubeQueryDefinition subQuery=createSubCubeQuery();
      if (subQuery != null) {
        return subQuery;
      }
    }
  }
  cubeQuery=ChartXTabUtil.getCubeElementFactory().createCubeQuery(cubeHandle.getQualifiedName());
  initBindings(cubeQuery,cubeHandle);
  List sdList=getAllSeriesDefinitions(cm);
  for (int i=0; i < sdList.size(); i++) {
    SeriesDefinition sd=(SeriesDefinition)sdList.get(i);
    List queryList=sd.getDesignTimeSeries().getDataDefinition();
    for (int j=0; j < queryList.size(); j++) {
      Query query=(Query)queryList.get(j);
      bindSeriesQuery(query,cubeQuery,cubeHandle);
    }
    bindSeriesQuery(sd.getQuery(),cubeQuery,cubeHandle);
  }
  Collection levelsInOrder=getAllLevelsInHierarchyOrder(cubeHandle,cubeQuery);
  for (Iterator measureNames=registeredMeasures.keySet().iterator(); measureNames.hasNext(); ) {
    Binding binding=(Binding)registeredBindings.get(measureNames.next());
    if (binding != null && binding.getAggregatOns().isEmpty()) {
      for (Iterator levels=levelsInOrder.iterator(); levels.hasNext(); ) {
        ILevelDefinition level=(ILevelDefinition)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;
}