Program: 73400
Project: 73400
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 (!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);
      }
 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) {
    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);
      }
 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);
    }
  }
}