Program: 72901
Project: 72901
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 != null) {
      if (colBinding == null) {
        bindingName=StructureFactory.newComputedColumn(handle,expr.replaceAll("String_Node_Str","String_Node_Str")).getName();
        colBinding=new Binding(bindingName);
        colBinding.setDataType(org.eclipse.birt.core.data.DataType.ANY_TYPE);
        colBinding.setExpression(new ScriptExpression(expr));
        registeredBindings.put(bindingName,colBinding);
        registeredQueries.put(bindingName,expr);
        registeredBindings.put(expr,colBinding);
      }
 else {
        bindingName=colBinding.getBindingName();
        expr=registeredQueries.get(bindingName);
      }
      if (!cubeQuery.getBindings().contains(colBinding)) {
        cubeQuery.addBinding(colBinding);
      }
      if (ChartXTabUtil.isBinding(expr,true)) {
        bindSeriesQuery(ChartXTabUtil.getBindingName(expr,true),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().getQualifiedName());
        }
 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);
    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 != null) {
      if (colBinding == null) {
        bindingName=StructureFactory.newComputedColumn(handle,expr.replaceAll("String_Node_Str","String_Node_Str")).getName();
        colBinding=new Binding(bindingName);
        colBinding.setDataType(org.eclipse.birt.core.data.DataType.ANY_TYPE);
        colBinding.setExpression(new ScriptExpression(expr));
        registeredBindings.put(bindingName,colBinding);
        registeredQueries.put(bindingName,expr);
        registeredBindings.put(expr,colBinding);
      }
 else {
        bindingName=colBinding.getBindingName();
        expr=registeredQueries.get(bindingName);
      }
      if (!cubeQuery.getBindings().contains(colBinding)) {
        cubeQuery.addBinding(colBinding);
      }
      if (ChartXTabUtil.isBinding(expr,true)) {
        bindSeriesQuery(ChartXTabUtil.getBindingName(expr,true),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());
          }
        }
      }
    }
  }
}