Program: 68104
Project: 68104
Buggy source:
/** 
 * @param query
 * @param categorySD
 * @param categoryGroupDefinition
 * @param valueExprMap
 */
private void bindSortOnCategorySeries(BaseQueryDefinition query,SeriesDefinition categorySD,GroupDefinition categoryGroupDefinition,Map<String,String[]> valueExprMap) throws ChartException {
  String baseSortExpr=getValidSortExpr(categorySD);
  if (!categorySD.isSetSorting() || baseSortExpr == null) {
    return;
  }
  SortDefinition sd=new SortDefinition();
  if (categorySD.getSortLocale() != null) {
    sd.setSortLocale(new ULocale(categorySD.getSortLocale()));
  }
  if (!categorySD.isSetSortStrength()) {
    sd.setSortStrength(ISortDefinition.DEFAULT_SORT_STRENGTH);
  }
 else {
    sd.setSortStrength(categorySD.getSortStrength());
  }
  sd.setSortDirection(ChartReportItemUtil.convertToDtESortDirection(categorySD.getSorting()));
  String sortExpr=baseSortExpr;
  if (ChartReportItemUtil.isBaseGroupingDefined(categorySD)) {
    categoryGroupDefinition.addSort(sd);
    String baseExpr=categorySD.getDesignTimeSeries().getDataDefinition().get(0).getDefinition();
    if (baseExpr.equals(getValidSortExpr(categorySD))) {
      sd.setExpression(categoryGroupDefinition.getKeyExpression());
      return;
    }
 else {
      String[] nameNewExprArray=valueExprMap.get(baseSortExpr);
      if (nameNewExprArray != null && nameNewExprArray.length == 2) {
        sortExpr=nameNewExprArray[1];
        exprCodec.decode(sortExpr);
        sd.setExpression(ChartReportItemUtil.adaptExpression(exprCodec,modelAdapter,false));
        return;
      }
 else {
        sortExpr=baseSortExpr;
        exprCodec.decode(sortExpr);
        String name=generateUniqueBindingName(exprCodec.getExpression());
        Binding binding=new Binding(name);
        try {
          query.addBinding(binding);
          binding.setExpression(ChartReportItemUtil.adaptExpression(exprCodec,modelAdapter,false));
          binding.setDataType(org.eclipse.birt.core.data.DataType.ANY_TYPE);
          binding.addAggregateOn(categoryGroupDefinition.getName());
          binding.setExportable(false);
        }
 catch (        DataException e) {
          throw new ChartException(ChartReportItemPlugin.ID,ChartException.DATA_BINDING,e);
        }
        String baseAggFunExpr=categorySD.getGrouping().getAggregateExpression();
        binding.setAggrFunction(ChartReportItemUtil.convertToDtEAggFunction(baseAggFunExpr));
        IAggregateFunction aFunc=PluginSettings.instance().getAggregateFunction(baseAggFunExpr);
        if (aFunc.getParametersCount() > 0) {
          String[] parameters=categorySD.getGrouping().getAggregateParameters().toArray(new String[1]);
          for (int i=0; i < parameters.length && i < aFunc.getParametersCount(); i++) {
            String param=parameters[i];
            binding.addArgument(new ScriptExpression(param));
          }
        }
        sd.setExpression(ExpressionUtil.createRowExpression(binding.getBindingName()));
      }
    }
  }
 else {
    sortExpr=baseSortExpr;
    query.addSort(sd);
    exprCodec.decode(sortExpr);
    sd.setExpression(ChartReportItemUtil.adaptExpression(exprCodec,modelAdapter,false));
  }
}

Fixed version (ground truth):
/** 
 * @param query
 * @param categorySD
 * @param categoryGroupDefinition
 * @param valueExprMap
 */
private void bindSortOnCategorySeries(BaseQueryDefinition query,SeriesDefinition categorySD,GroupDefinition categoryGroupDefinition,Map<String,String[]> valueExprMap,Axis[] orthAxisArray) throws ChartException {
  String baseSortExpr=getValidSortExpr(categorySD);
  if (!categorySD.isSetSorting() || baseSortExpr == null) {
    return;
  }
  SortDefinition sd=new SortDefinition();
  if (categorySD.getSortLocale() != null) {
    sd.setSortLocale(new ULocale(categorySD.getSortLocale()));
  }
  if (!categorySD.isSetSortStrength()) {
    sd.setSortStrength(ISortDefinition.DEFAULT_SORT_STRENGTH);
  }
 else {
    sd.setSortStrength(categorySD.getSortStrength());
  }
  sd.setSortDirection(ChartReportItemUtil.convertToDtESortDirection(categorySD.getSorting()));
  String sortExpr=baseSortExpr;
  if (ChartReportItemUtil.isBaseGroupingDefined(categorySD)) {
    categoryGroupDefinition.addSort(sd);
    String baseExpr=categorySD.getDesignTimeSeries().getDataDefinition().get(0).getDefinition();
    if (baseExpr.equals(getValidSortExpr(categorySD))) {
      sd.setExpression(categoryGroupDefinition.getKeyExpression());
      return;
    }
 else {
      String[] nameNewExprArray=valueExprMap.get(baseSortExpr);
      if (nameNewExprArray != null && nameNewExprArray.length == 2) {
        sortExpr=nameNewExprArray[1];
        exprCodec.decode(sortExpr);
        sd.setExpression(ChartReportItemUtil.adaptExpression(exprCodec,modelAdapter,false));
        return;
      }
 else {
        sortExpr=baseSortExpr;
        exprCodec.decode(sortExpr);
        String name=generateUniqueBindingName(exprCodec.getExpression());
        Binding binding=new Binding(name);
        try {
          query.addBinding(binding);
          binding.setExpression(ChartReportItemUtil.adaptExpression(exprCodec,modelAdapter,false));
          binding.setDataType(org.eclipse.birt.core.data.DataType.ANY_TYPE);
          binding.setExportable(false);
        }
 catch (        DataException e) {
          throw new ChartException(ChartReportItemPlugin.ID,ChartException.DATA_BINDING,e);
        }
        if (isYSeriesExpression(sortExpr)) {
          String aggFunc=getAggFunExpr(sortExpr,categorySD,orthAxisArray);
          if (aggFunc != null) {
            try {
              binding.addAggregateOn(categoryGroupDefinition.getName());
            }
 catch (            DataException e) {
              throw new ChartException(ChartReportItemPlugin.ID,ChartException.DATA_BINDING,e);
            }
            binding.setAggrFunction(ChartReportItemUtil.convertToDtEAggFunction(aggFunc));
            IAggregateFunction aFunc=PluginSettings.instance().getAggregateFunction(aggFunc);
            if (aFunc.getParametersCount() > 0) {
              String[] parameters=categorySD.getGrouping().getAggregateParameters().toArray(new String[1]);
              for (int i=0; i < parameters.length && i < aFunc.getParametersCount(); i++) {
                String param=parameters[i];
                binding.addArgument(new ScriptExpression(param));
              }
            }
          }
        }
        sd.setExpression(ExpressionUtil.createRowExpression(binding.getBindingName()));
      }
    }
  }
 else {
    sortExpr=baseSortExpr;
    query.addSort(sd);
    exprCodec.decode(sortExpr);
    sd.setExpression(ChartReportItemUtil.adaptExpression(exprCodec,modelAdapter,false));
  }
}