Program: 65469
Project: 65469
Buggy source:
/** 
 * Populate grouping to the query.
 * @param cx
 * @throws DataException
 */
private void populateGrouping(ScriptContext cx,SortingOptimizer opt) throws DataException {
  List groups=this.baseQueryDefn.getGroups();
  if (groups != null && !groups.isEmpty()) {
    boolean needSortingOnGroupKeys=needSortingOnGroupKeys();
    IQuery.GroupSpec[] groupSpecs=new IQuery.GroupSpec[groups.size()];
    Iterator it=groups.iterator();
    for (int i=0; it.hasNext(); i++) {
      IGroupDefinition src=(IGroupDefinition)it.next();
      validateGroupExpression(src);
      String expr=getDataSetGroupKeyExpression(src);
      String groupName=populateGroupName(i,expr);
      int dataType=getColumnDataType(cx,getGroupKeyExpression(src));
      boolean doGroupSorting=false;
      if (this.session.getEngineContext().getMode() == DataEngineContext.MODE_UPDATE) {
        doGroupSorting=true;
      }
 else       if (src.getSortDirection() == IGroupDefinition.NO_SORT) {
        doGroupSorting=false;
      }
 else {
        doGroupSorting=needSortingOnGroupKeys;
      }
      IQuery.GroupSpec dest=QueryExecutorUtil.groupDefnToSpec(cx,src,expr,groupName,-1,dataType,doGroupSorting);
      groupSpecs[i]=dest;
      this.temporaryComputedColumns.add(getComputedColumnInstance(cx,groupSpecs[i].getInterval(),src,expr,groupName,dest,dataType));
    }
    if (opt.acceptGroupSorting()) {
      for (int i=0; i < groupSpecs.length; i++) {
        IQuery.GroupSpec spec=groupSpecs[i];
        spec.setSortDirection(IGroupDefinition.NO_SORT);
      }
    }
    odiQuery.setGrouping(Arrays.asList(groupSpecs));
  }
}

Fixed version (ground truth):
/** 
 * Populate grouping to the query.
 * @param cx
 * @throws DataException
 */
private void populateGrouping(ScriptContext cx,SortingOptimizer opt) throws DataException {
  List groups=this.baseQueryDefn.getGroups();
  if (groups != null && !groups.isEmpty()) {
    IQuery.GroupSpec[] groupSpecs=new IQuery.GroupSpec[groups.size()];
    Iterator it=groups.iterator();
    for (int i=0; it.hasNext(); i++) {
      IGroupDefinition src=(IGroupDefinition)it.next();
      validateGroupExpression(src);
      String expr=getDataSetGroupKeyExpression(src);
      String groupName=populateGroupName(i,expr);
      int dataType=getColumnDataType(cx,getGroupKeyExpression(src));
      boolean doGroupSorting=false;
      if (this.session.getEngineContext().getMode() == DataEngineContext.MODE_UPDATE) {
        doGroupSorting=true;
      }
 else       if (src.getSortDirection() == IGroupDefinition.NO_SORT) {
        doGroupSorting=false;
      }
 else {
        doGroupSorting=this.baseQueryDefn.getQueryExecutionHints().doSortBeforeGrouping();
      }
      IQuery.GroupSpec dest=QueryExecutorUtil.groupDefnToSpec(cx,src,expr,groupName,-1,dataType,doGroupSorting);
      groupSpecs[i]=dest;
      this.temporaryComputedColumns.add(getComputedColumnInstance(cx,groupSpecs[i].getInterval(),src,expr,groupName,dest,dataType));
    }
    if (opt.acceptGroupSorting()) {
      for (int i=0; i < groupSpecs.length; i++) {
        IQuery.GroupSpec spec=groupSpecs[i];
        spec.setSortDirection(IGroupDefinition.NO_SORT);
      }
    }
    odiQuery.setGrouping(Arrays.asList(groupSpecs));
  }
}