Program: 68105
Project: 68105
Buggy source:
/** 
 * @param query
 * @param categorySD
 * @param orthSD
 * @param orthAxisArray
 * @return
 * @throws ChartException
 */
private GroupDefinition initYGroupingNSortKey(BaseQueryDefinition query,SeriesDefinition categorySD,SeriesDefinition orthSD,Axis[] orthAxisArray) throws ChartException {
  GroupDefinition yGroupingDefinition=createOrthogonalGroupingDefinition(orthSD);
  if (yGroupingDefinition != null) {
    query.addGroup(yGroupingDefinition);
    if (!orthSD.isSetSorting()) {
      return yGroupingDefinition;
    }
    SortDefinition sortDefinition=new SortDefinition();
    if (categorySD.getSortLocale() != null) {
      sortDefinition.setSortLocale(new ULocale(categorySD.getSortLocale()));
    }
    if (!categorySD.isSetSortStrength()) {
      sortDefinition.setSortStrength(ISortDefinition.DEFAULT_SORT_STRENGTH);
    }
 else {
      sortDefinition.setSortStrength(categorySD.getSortStrength());
    }
    sortDefinition.setSortDirection(ChartReportItemUtil.convertToDtESortDirection(orthSD.getSorting()));
    String sortKey=null;
    if (orthSD.getSortKey() != null && orthSD.getSortKey().getDefinition() != null) {
      sortKey=orthSD.getSortKey().getDefinition();
    }
    if (sortKey == null || yGroupingDefinition.getKeyExpression().equals(sortKey)) {
      sortDefinition.setExpression(yGroupingDefinition.getKeyExpression());
    }
 else {
      exprCodec.decode(sortKey);
      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(yGroupingDefinition.getName());
        binding.setExportable(false);
      }
 catch (      DataException e) {
        throw new ChartException(ChartReportItemPlugin.ID,ChartException.DATA_BINDING,e);
      }
      String[] vsExprs=ChartUtil.getValueSeriesExpressions(fChartModel);
      boolean isYSeriesExpression=false;
      for (int i=0; i < vsExprs.length; i++) {
        if (vsExprs[i].equals(sortKey)) {
          isYSeriesExpression=true;
          break;
        }
      }
      if (isYSeriesExpression) {
        String aggFunc=getAggFunExpr(sortKey,categorySD,orthAxisArray);
        if (aggFunc != null) {
          binding.setAggrFunction(ChartReportItemUtil.convertToDtEAggFunction(aggFunc));
          IAggregateFunction aFunc=PluginSettings.instance().getAggregateFunction(aggFunc);
          if (aFunc.getParametersCount() > 0) {
            String[] parameters=ChartUtil.getAggFunParameters(orthSD,categorySD,null);
            for (int i=0; i < parameters.length && i < aFunc.getParametersCount(); i++) {
              String param=parameters[i];
              binding.addArgument(new ScriptExpression(param));
            }
          }
        }
      }
      sortDefinition.setExpression(ExpressionUtil.createRowExpression(binding.getBindingName()));
    }
    yGroupingDefinition.addSort(sortDefinition);
  }
  return yGroupingDefinition;
}

Fixed version (ground truth):
/** 
 * @param query
 * @param categorySD
 * @param orthSD
 * @param orthAxisArray
 * @return
 * @throws ChartException
 */
private GroupDefinition initYGroupingNSortKey(BaseQueryDefinition query,SeriesDefinition categorySD,SeriesDefinition orthSD,Axis[] orthAxisArray) throws ChartException {
  GroupDefinition yGroupingDefinition=createOrthogonalGroupingDefinition(orthSD);
  if (yGroupingDefinition != null) {
    query.addGroup(yGroupingDefinition);
    if (!orthSD.isSetSorting()) {
      return yGroupingDefinition;
    }
    SortDefinition sortDefinition=new SortDefinition();
    if (categorySD.getSortLocale() != null) {
      sortDefinition.setSortLocale(new ULocale(categorySD.getSortLocale()));
    }
    if (!categorySD.isSetSortStrength()) {
      sortDefinition.setSortStrength(ISortDefinition.DEFAULT_SORT_STRENGTH);
    }
 else {
      sortDefinition.setSortStrength(categorySD.getSortStrength());
    }
    sortDefinition.setSortDirection(ChartReportItemUtil.convertToDtESortDirection(orthSD.getSorting()));
    String sortKey=null;
    if (orthSD.getSortKey() != null && orthSD.getSortKey().getDefinition() != null) {
      sortKey=orthSD.getSortKey().getDefinition();
    }
    if (sortKey == null || yGroupingDefinition.getKeyExpression().equals(sortKey)) {
      sortDefinition.setExpression(yGroupingDefinition.getKeyExpression());
    }
 else {
      exprCodec.decode(sortKey);
      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(sortKey)) {
        String aggFunc=getAggFunExpr(sortKey,categorySD,orthAxisArray);
        if (aggFunc != null) {
          try {
            binding.addAggregateOn(yGroupingDefinition.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=ChartUtil.getAggFunParameters(orthSD,categorySD,null);
            for (int i=0; i < parameters.length && i < aFunc.getParametersCount(); i++) {
              String param=parameters[i];
              binding.addArgument(new ScriptExpression(param));
            }
          }
        }
      }
      sortDefinition.setExpression(ExpressionUtil.createRowExpression(binding.getBindingName()));
    }
    yGroupingDefinition.addSort(sortDefinition);
  }
  return yGroupingDefinition;
}