Program: 67130
Project: 67130
Buggy source:
private void setQueryExpression(String expression){
  if (ChartUIConstants.QUERY_VALUE.equals(queryType)) {
    if (!(context.getChartType() instanceof GanttChart) && !context.getDataServiceProvider().checkState(IDataServiceProvider.SHARE_QUERY) && context.getDataServiceProvider().checkState(IDataServiceProvider.HAS_DATA_SET)) {
      if (context.getDataServiceProvider().getDataType(expression) == DataType.DATE_TIME_LITERAL) {
        ChartAdapter.beginIgnoreNotifications();
        if (query.getGrouping() == null) {
          query.setGrouping(DataFactoryImpl.init().createSeriesGrouping());
        }
        SeriesGrouping group=query.getGrouping();
        group.setEnabled(true);
        group.setAggregateExpression("String_Node_Str");
        ChartAdapter.endIgnoreNotifications();
      }
    }
  }
 else   if (ChartUIConstants.QUERY_CATEGORY.equals(queryType)) {
    DataType type=context.getDataServiceProvider().getDataType(expression);
    ChartAdapter.beginIgnoreNotifications();
    if (seriesdefinition.getGrouping() == null) {
      seriesdefinition.setGrouping(DataFactoryImpl.init().createSeriesGrouping());
    }
    seriesdefinition.getGrouping().setGroupType(type);
    if (type == DataType.DATE_TIME_LITERAL) {
      seriesdefinition.getGrouping().setGroupingUnit(GroupingUnitType.YEARS_LITERAL);
    }
    if (ChartUIUtil.hasLimitOnCategorySortKey(context) && ChartUtil.hasSorting(seriesdefinition)) {
      Query sortQuery=seriesdefinition.getSortKey();
      if (sortQuery == null) {
        sortQuery=QueryImpl.create(expression);
        sortQuery.eAdapters().addAll(seriesdefinition.eAdapters());
        seriesdefinition.setSortKey(sortQuery);
      }
 else {
        sortQuery.setDefinition(expression);
      }
    }
    ChartAdapter.endIgnoreNotifications();
  }
 else   if (ChartUIConstants.QUERY_OPTIONAL.equals(queryType)) {
    ChartAdapter.beginIgnoreNotifications();
    if (expression == null || expression.trim().length() == 0) {
      seriesdefinition.eUnset(DataPackage.eINSTANCE.getSeriesDefinition_Sorting());
      if (seriesdefinition.getSortKey() != null) {
        seriesdefinition.getSortKey().setDefinition(null);
      }
    }
 else {
      if (seriesdefinition.getSortKey() != null && seriesdefinition.getSortKey().getDefinition() != null && seriesdefinition.getSortKey().getDefinition().equals(query.getDefinition())) {
        seriesdefinition.getSortKey().setDefinition(expression);
      }
      DataType type=context.getDataServiceProvider().getDataType(expression);
      if (query.getGrouping() == null) {
        query.setGrouping(DataFactoryImpl.init().createSeriesGrouping());
      }
      query.getGrouping().setGroupType(type);
      if (type == DataType.DATE_TIME_LITERAL && context.getDataServiceProvider().checkState(IDataServiceProvider.HAS_DATA_SET)) {
        query.getGrouping().setGroupingUnit(GroupingUnitType.YEARS_LITERAL);
      }
    }
    ChartAdapter.endIgnoreNotifications();
  }
  if (query != null) {
    query.setDefinition(expression);
  }
 else {
    query=QueryImpl.create(expression);
    query.eAdapters().addAll(seriesdefinition.eAdapters());
    seriesdefinition.setQuery(query);
  }
}

Fixed version (ground truth):
private void setQueryExpression(String expression){
  if (ChartUIConstants.QUERY_VALUE.equals(queryType)) {
    if (!(context.getChartType() instanceof GanttChart) && !context.getDataServiceProvider().checkState(IDataServiceProvider.SHARE_QUERY) && context.getDataServiceProvider().checkState(IDataServiceProvider.HAS_DATA_SET)) {
      if (context.getDataServiceProvider().getDataType(expression) == DataType.DATE_TIME_LITERAL) {
        SeriesGrouping basegrouping=ChartUtil.getBaseSeriesDefinitions(context.getModel()).get(0).getGrouping();
        if (basegrouping != null && basegrouping.isEnabled() && !ChartUIUtil.isDataTimeSupportedAgg(basegrouping.getAggregateExpression())) {
          ChartAdapter.beginIgnoreNotifications();
          if (query.getGrouping() == null) {
            query.setGrouping(DataFactoryImpl.init().createSeriesGrouping());
          }
          SeriesGrouping group=query.getGrouping();
          group.setEnabled(true);
          if (!ChartUIUtil.isDataTimeSupportedAgg(group.getAggregateExpression())) {
            group.setAggregateExpression("String_Node_Str");
          }
          ChartAdapter.endIgnoreNotifications();
        }
      }
    }
  }
 else   if (ChartUIConstants.QUERY_CATEGORY.equals(queryType)) {
    DataType type=context.getDataServiceProvider().getDataType(expression);
    ChartAdapter.beginIgnoreNotifications();
    if (seriesdefinition.getGrouping() == null) {
      seriesdefinition.setGrouping(DataFactoryImpl.init().createSeriesGrouping());
    }
    seriesdefinition.getGrouping().setGroupType(type);
    if (type == DataType.DATE_TIME_LITERAL) {
      seriesdefinition.getGrouping().setGroupingUnit(GroupingUnitType.YEARS_LITERAL);
    }
    if (ChartUIUtil.hasLimitOnCategorySortKey(context) && ChartUtil.hasSorting(seriesdefinition)) {
      Query sortQuery=seriesdefinition.getSortKey();
      if (sortQuery == null) {
        sortQuery=QueryImpl.create(expression);
        sortQuery.eAdapters().addAll(seriesdefinition.eAdapters());
        seriesdefinition.setSortKey(sortQuery);
      }
 else {
        sortQuery.setDefinition(expression);
      }
    }
    ChartAdapter.endIgnoreNotifications();
  }
 else   if (ChartUIConstants.QUERY_OPTIONAL.equals(queryType)) {
    ChartAdapter.beginIgnoreNotifications();
    if (expression == null || expression.trim().length() == 0) {
      seriesdefinition.eUnset(DataPackage.eINSTANCE.getSeriesDefinition_Sorting());
      if (seriesdefinition.getSortKey() != null) {
        seriesdefinition.getSortKey().setDefinition(null);
      }
    }
 else {
      if (seriesdefinition.getSortKey() != null && seriesdefinition.getSortKey().getDefinition() != null && seriesdefinition.getSortKey().getDefinition().equals(query.getDefinition())) {
        seriesdefinition.getSortKey().setDefinition(expression);
      }
      DataType type=context.getDataServiceProvider().getDataType(expression);
      if (query.getGrouping() == null) {
        query.setGrouping(DataFactoryImpl.init().createSeriesGrouping());
      }
      query.getGrouping().setGroupType(type);
      if (type == DataType.DATE_TIME_LITERAL && context.getDataServiceProvider().checkState(IDataServiceProvider.HAS_DATA_SET)) {
        query.getGrouping().setGroupingUnit(GroupingUnitType.YEARS_LITERAL);
      }
    }
    ChartAdapter.endIgnoreNotifications();
  }
  if (query != null) {
    query.setDefinition(expression);
  }
 else {
    query=QueryImpl.create(expression);
    query.eAdapters().addAll(seriesdefinition.eAdapters());
    seriesdefinition.setQuery(query);
  }
}