Program: 72162
Project: 72162
Buggy source:
/** 
 * Adds measure or row/column edge according to query expression.
 */
private void bindSeriesQuery(String expr,ICubeQueryDefinition cubeQuery,CubeHandle cube) throws BirtException {
  if (expr != null && expr.length() > 0) {
    String bindingName=ChartXTabUtil.getBindingName(expr,true);
    Binding colBinding=null;
    if (bindingName != null) {
      List<String> nameList=ChartXTabUtil.getBindingNameList(expr);
      if (nameList.size() > 1) {
        for (        String bn : nameList) {
          bindSeriesQuery(ExpressionUtil.createJSDataExpression(bn),cubeQuery,cube);
        }
        return;
      }
      colBinding=registeredBindings.get(bindingName);
    }
    if (colBinding != null) {
      bindingName=colBinding.getBindingName();
      expr=registeredQueries.get(bindingName);
      if (!cubeQuery.getBindings().contains(colBinding)) {
        cubeQuery.addBinding(colBinding);
      }
      if (ChartXTabUtil.isBinding(expr,true)) {
        bindSeriesQuery(expr,cubeQuery,cube);
        return;
      }
      String measure=ChartXTabUtil.getMeasureName(expr);
      if (measure != null) {
        if (registeredMeasures.containsKey(bindingName)) {
          return;
        }
        IMeasureDefinition mDef=cubeQuery.createMeasure(measure);
        String aggFun=DataAdapterUtil.adaptModelAggregationType(cube.getMeasure(measure).getFunction());
        mDef.setAggrFunction(aggFun);
        registeredMeasures.put(bindingName,mDef);
      }
 else       if (ChartXTabUtil.isDimensionExpresion(expr)) {
        if (registeredLevels.containsKey(bindingName)) {
          return;
        }
        String[] levels=ChartXTabUtil.getLevelNameFromDimensionExpression(expr);
        String dimensionName=levels[0];
        final int edgeType=getEdgeType(dimensionName);
        IEdgeDefinition edge=cubeQuery.getEdge(edgeType);
        IHierarchyDefinition hieDef=null;
        if (edge == null) {
          edge=cubeQuery.createEdge(edgeType);
          IDimensionDefinition dimDef=edge.createDimension(dimensionName);
          hieDef=dimDef.createHierarchy(cube.getDimension(dimDef.getName()).getDefaultHierarchy().getName());
        }
 else {
          hieDef=(IHierarchyDefinition)((IDimensionDefinition)edge.getDimensions().get(0)).getHierarchy().get(0);
        }
        boolean bMultipleLevels=!hieDef.getLevels().isEmpty();
        ILevelDefinition levelDef=hieDef.createLevel(levels[1]);
        registeredLevels.put(bindingName,levelDef);
        LevelHandle levelHandle=handle.getModuleHandle().findLevel(levelDef.getHierarchy().getDimension().getName() + "String_Node_Str" + levelDef.getName());
        registeredLevelHandles.put(levelHandle,levelDef);
        if (bMultipleLevels) {
          Iterator levelsInOrder=getAllLevelsInHierarchyOrder(cube,cubeQuery).iterator();
          hieDef.getLevels().clear();
          while (levelsInOrder.hasNext()) {
            ILevelDefinition level=(ILevelDefinition)levelsInOrder.next();
            hieDef.createLevel(level.getName());
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Adds measure or row/column edge according to query expression.
 */
private void bindSeriesQuery(String expr,ICubeQueryDefinition cubeQuery,CubeHandle cube) throws BirtException {
  if (expr != null && expr.length() > 0) {
    String bindingName=ChartXTabUtil.getBindingName(expr,true);
    IBinding colBinding=null;
    if (bindingName != null) {
      List<String> nameList=ChartXTabUtil.getBindingNameList(expr);
      if (nameList.size() > 1) {
        for (        String bn : nameList) {
          bindSeriesQuery(ExpressionUtil.createJSDataExpression(bn),cubeQuery,cube);
        }
        return;
      }
      colBinding=registeredBindings.get(bindingName);
    }
    if (colBinding != null) {
      bindingName=colBinding.getBindingName();
      expr=registeredQueries.get(bindingName);
      if (!cubeQuery.getBindings().contains(colBinding)) {
        cubeQuery.addBinding(colBinding);
      }
      if (ChartXTabUtil.isBinding(expr,true)) {
        bindSeriesQuery(expr,cubeQuery,cube);
        return;
      }
      String measure=ChartXTabUtil.getMeasureName(expr);
      if (measure != null) {
        if (registeredMeasures.containsKey(bindingName)) {
          return;
        }
        IMeasureDefinition mDef=cubeQuery.createMeasure(measure);
        String aggFun=DataAdapterUtil.adaptModelAggregationType(cube.getMeasure(measure).getFunction());
        mDef.setAggrFunction(aggFun);
        registeredMeasures.put(bindingName,mDef);
      }
 else       if (ChartXTabUtil.isDimensionExpresion(expr)) {
        if (registeredLevels.containsKey(bindingName)) {
          return;
        }
        String[] levels=ChartXTabUtil.getLevelNameFromDimensionExpression(expr);
        String dimensionName=levels[0];
        final int edgeType=getEdgeType(dimensionName);
        IEdgeDefinition edge=cubeQuery.getEdge(edgeType);
        IHierarchyDefinition hieDef=null;
        if (edge == null) {
          edge=cubeQuery.createEdge(edgeType);
          IDimensionDefinition dimDef=edge.createDimension(dimensionName);
          hieDef=dimDef.createHierarchy(cube.getDimension(dimDef.getName()).getDefaultHierarchy().getName());
        }
 else {
          hieDef=(IHierarchyDefinition)((IDimensionDefinition)edge.getDimensions().get(0)).getHierarchy().get(0);
        }
        boolean bMultipleLevels=!hieDef.getLevels().isEmpty();
        ILevelDefinition levelDef=hieDef.createLevel(levels[1]);
        registeredLevels.put(bindingName,levelDef);
        LevelHandle levelHandle=handle.getModuleHandle().findLevel(levelDef.getHierarchy().getDimension().getName() + "String_Node_Str" + levelDef.getName());
        registeredLevelHandles.put(levelHandle,levelDef);
        if (bMultipleLevels) {
          Iterator levelsInOrder=getAllLevelsInHierarchyOrder(cube,cubeQuery).iterator();
          hieDef.getLevels().clear();
          while (levelsInOrder.hasNext()) {
            ILevelDefinition level=(ILevelDefinition)levelsInOrder.next();
            hieDef.createLevel(level.getName());
          }
        }
      }
    }
  }
}