Program: 71626
Project: 71626
Buggy source:
/** 
 * Update query expression for sharing query with table.
 * @param expression
 */
private void updateQueryForSharedBinding(String expression){
  Object[] data=(Object[])cmbDefinition.getData();
  if (data != null && data.length > 0) {
    String expr=expression;
    if (ChartUIConstants.QUERY_CATEGORY.equals(queryType) || ChartUIConstants.QUERY_OPTIONAL.equals(queryType)) {
      boolean isGroupExpr=false;
      for (int i=0; i < data.length; i++) {
        ColumnBindingInfo chi=(ColumnBindingInfo)data[i];
        int type=chi.getColumnType();
        if (type == ColumnBindingInfo.GROUP_COLUMN) {
          String groupRegex=ChartUtil.createRegularRowExpression(chi.getName(),false);
          String regex=ChartUtil.createRegularRowExpression(chi.getName(),true);
          if (expression.matches(regex)) {
            isGroupExpr=true;
            expr=expression.replaceAll(groupRegex,chi.getExpression());
            break;
          }
        }
      }
      if (ChartUIConstants.QUERY_CATEGORY.equals(queryType)) {
        if (isGroupExpr) {
          seriesdefinition.getGrouping().setAggregateExpression(null);
          seriesdefinition.getGrouping().setEnabled(true);
        }
 else {
          seriesdefinition.getGrouping().setEnabled(false);
        }
      }
    }
 else     if (ChartUIConstants.QUERY_VALUE.equals(queryType)) {
      boolean isAggregationExpr=false;
      ColumnBindingInfo chi=null;
      for (int i=0; i < data.length; i++) {
        chi=(ColumnBindingInfo)data[i];
        int type=chi.getColumnType();
        if (type == ColumnBindingInfo.AGGREGATE_COLUMN) {
          String aggRegex=ChartUtil.createRegularRowExpression(chi.getName(),false);
          String regex=ChartUtil.createRegularRowExpression(chi.getName(),true);
          if (expression.matches(regex)) {
            isAggregationExpr=true;
            expr=expression.replaceAll(aggRegex,chi.getExpression());
            break;
          }
        }
      }
      if (isAggregationExpr) {
        seriesdefinition.getGrouping().setEnabled(true);
        seriesdefinition.getGrouping().setAggregateExpression(chi.getChartAggExpression());
      }
 else {
        seriesdefinition.getGrouping().setEnabled(false);
        seriesdefinition.getGrouping().setAggregateExpression(null);
      }
    }
    setQueryExpression(expr);
  }
 else {
    setQueryExpression(expression);
  }
}

Fixed version (ground truth):
/** 
 * Update query expression for sharing query with table.
 * @param expression
 */
private void updateQueryForSharedBinding(String expression){
  Object[] data=(Object[])cmbDefinition.getData();
  if (data != null && data.length > 0) {
    String expr=expression;
    if (ChartUIConstants.QUERY_CATEGORY.equals(queryType) || ChartUIConstants.QUERY_OPTIONAL.equals(queryType)) {
      boolean isGroupExpr=false;
      for (int i=0; i < data.length; i++) {
        ColumnBindingInfo chi=(ColumnBindingInfo)data[i];
        int type=chi.getColumnType();
        if (type == ColumnBindingInfo.GROUP_COLUMN) {
          String groupRegex=ChartUtil.createRegularRowExpression(chi.getName(),false);
          String regex=ChartUtil.createRegularRowExpression(chi.getName(),true);
          if (expression.matches(regex)) {
            isGroupExpr=true;
            expr=expression.replaceAll(groupRegex,chi.getExpression());
            break;
          }
        }
      }
      if (ChartUIConstants.QUERY_CATEGORY.equals(queryType)) {
        if (isGroupExpr) {
          seriesdefinition.getGrouping().setEnabled(true);
        }
 else {
          seriesdefinition.getGrouping().setEnabled(false);
        }
      }
    }
 else     if (ChartUIConstants.QUERY_VALUE.equals(queryType)) {
      boolean isAggregationExpr=false;
      ColumnBindingInfo chi=null;
      for (int i=0; i < data.length; i++) {
        chi=(ColumnBindingInfo)data[i];
        int type=chi.getColumnType();
        if (type == ColumnBindingInfo.AGGREGATE_COLUMN) {
          String aggRegex=ChartUtil.createRegularRowExpression(chi.getName(),false);
          String regex=ChartUtil.createRegularRowExpression(chi.getName(),true);
          if (expression.matches(regex)) {
            isAggregationExpr=true;
            expr=expression.replaceAll(aggRegex,chi.getExpression());
            break;
          }
        }
      }
      if (isAggregationExpr) {
        seriesdefinition.getGrouping().setEnabled(true);
        seriesdefinition.getGrouping().setAggregateExpression(chi.getChartAggExpression());
      }
 else {
        seriesdefinition.getGrouping().setEnabled(false);
        seriesdefinition.getGrouping().setAggregateExpression(null);
      }
    }
    setQueryExpression(expr);
  }
 else {
    setQueryExpression(expression);
  }
}