Program: 73233
Project: 73233
Buggy source:
/** 
 * Adds measure or row/column edge according to query expression. Besides, generates column bindings, replace them in chart queries and add them in query definition.
 */
private void bindSeriesQuery(Query query,ICubeQueryDefinition cubeQuery,CubeHandle cube) throws BirtException {
  String expr=query.getDefinition();
  if (expr != null && expr.length() > 0) {
    boolean bBindingExp=ChartXTabUtil.isBinding(expr,true);
    if (bBindingExp && !ChartXTabUtil.isBinding(expr,false)) {
      expr=ExpressionUtil.createJSDataExpression(ChartXTabUtil.getBindingName(expr,true));
    }
    Binding colBinding=(Binding)registeredBindings.get(expr);
    if (bBindingExp || colBinding == null) {
      String 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(expr,colBinding);
        registeredQueries.put(bindingName,expr);
      }
 else {
        bindingName=colBinding.getBindingName();
        expr=(String)registeredQueries.get(bindingName);
      }
      cubeQuery.addBinding(colBinding);
      String measure=getMeasure(expr);
      if (measure != null) {
        IMeasureDefinition mDef=cubeQuery.createMeasure(measure);
        String aggFun=DataAdapterUtil.adaptModelAggregationType(cube.getMeasure(measure).getFunction());
        mDef.setAggrFunction(aggFun);
        registeredMeasures.put(bindingName,mDef);
      }
 else       if (isReferenceToDimLevel(expr)) {
        String[] levels=getTargetLevel(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);
        }
        ILevelDefinition levelDef=hieDef.createLevel(levels[1]);
        registeredLevels.put(bindingName,levelDef);
        LevelHandle levelHandle=cube.getDimension(levelDef.getHierarchy().getDimension().getName()).getDefaultHierarchy().getLevel(levelDef.getName());
        registeredLevelHandles.put(levelHandle,levelDef);
      }
    }
    if (!bBindingExp) {
      String newExpr=ExpressionUtil.createJSDataExpression(colBinding.getBindingName());
      query.setDefinition(newExpr);
    }
  }
}

Fixed version (ground truth):
/** 
 * Adds measure or row/column edge according to query expression. Besides, generates column bindings, replace them in chart queries and add them in query definition.
 */
private void bindSeriesQuery(Query query,ICubeQueryDefinition cubeQuery,CubeHandle cube) throws BirtException {
  String expr=query.getDefinition();
  if (expr != null && expr.length() > 0) {
    String bindingName=ChartXTabUtil.getBindingName(expr,true);
    boolean bBindingExp=bindingName != null;
    if (bindingName != null && !ChartXTabUtil.isBinding(expr,false)) {
      expr=ExpressionUtil.createJSDataExpression(bindingName);
    }
    Binding colBinding=null;
    if (bindingName != null) {
      colBinding=(Binding)registeredBindings.get(bindingName);
    }
 else {
      colBinding=(Binding)registeredBindings.get(expr);
    }
    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=(String)registeredQueries.get(bindingName);
      }
      if (!cubeQuery.getBindings().contains(colBinding)) {
        cubeQuery.addBinding(colBinding);
      }
      String measure=ChartXTabUtil.getMeasureName(expr);
      if (measure != null) {
        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)) {
        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=cube.getDimension(levelDef.getHierarchy().getDimension().getName()).getDefaultHierarchy().getLevel(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());
          }
        }
      }
    }
    if (!bBindingExp && colBinding != null) {
      String newExpr=ExpressionUtil.createJSDataExpression(colBinding.getBindingName());
      query.setDefinition(newExpr);
    }
  }
}