Program: 75103
Project: 75103
Buggy source:
/** 
 * @param trans
 * @param groupLevel
 * @param cx
 * @throws DataException
 */
private void prepareGroup(IBaseQueryDefinition baseQuery,int groupLevel,Context cx) throws DataException {
  IBaseTransform trans=baseQuery;
  String groupName=IBaseExpression.GROUP_OVERALL;
  if (groupLevel != 0) {
    IGroupDefinition igd=(IGroupDefinition)((IBaseQueryDefinition)trans).getGroups().get(groupLevel - 1);
    trans=igd;
    groupName=igd.getName();
  }
  Collection exprCol=new ArrayList();
  Map resultSetExpressions=new HashMap();
  Map map=baseQuery.getBindings();
  if (map != null) {
    Iterator it=map.keySet().iterator();
    while (it.hasNext()) {
      Object key=it.next();
      IBinding icbe=((IBinding)map.get(key));
      if (icbe.getExpression() != null && icbe.getExpression().getGroupName().equals(groupName) && groupLevel != 0) {
        exprCol.add(icbe.getExpression());
        resultSetExpressions.put(key,icbe);
      }
 else       if (groupLevel == 0 && icbe.getAggregatOns().size() == 0) {
        exprCol.add(icbe.getExpression());
        resultSetExpressions.put(key,icbe);
      }
 else       if (groupLevel != 0 && icbe.getAggregatOns().contains(groupName)) {
        exprCol.add(icbe.getExpression());
        resultSetExpressions.put(key,icbe);
      }
    }
  }
  prepareExpressions(exprCol,groupLevel,false,true,cx);
  String key=null;
  if (trans instanceof IGroupDefinition) {
    IGroupDefinition gd=(IGroupDefinition)trans;
    key=gd.getKeyColumn() != null ? gd.getKeyColumn() : gd.getKeyExpression();
  }
  this.exprManager.addBindingExpr(key,resultSetExpressions,groupLevel);
  Collection subQueries=trans.getSubqueries();
  Iterator subIt=subQueries.iterator();
  while (subIt.hasNext()) {
    ISubqueryDefinition subquery=(ISubqueryDefinition)subIt.next();
    PreparedSubquery pq=new PreparedSubquery(this.session,this.dataEngineContext,subquery,queryService,groupLevel);
    subQueryMap.put(subquery.getName(),pq);
    subQueryDefnMap.put(subquery.getName(),new Object[]{subquery,new Integer(groupLevel)});
  }
}

Fixed version (ground truth):
/** 
 * @param trans
 * @param groupLevel
 * @param cx
 * @throws DataException
 */
private void prepareGroup(IBaseQueryDefinition baseQuery,int groupLevel,Context cx) throws DataException {
  IBaseTransform trans=baseQuery;
  String groupName=IBaseExpression.GROUP_OVERALL;
  if (groupLevel != 0) {
    IGroupDefinition igd=(IGroupDefinition)((IBaseQueryDefinition)trans).getGroups().get(groupLevel - 1);
    trans=igd;
    groupName=igd.getName();
  }
  Collection exprCol=new ArrayList();
  Map resultSetExpressions=new HashMap();
  Map map=baseQuery.getBindings();
  if (map != null) {
    Iterator it=map.keySet().iterator();
    while (it.hasNext()) {
      Object key=it.next();
      IBinding icbe=((IBinding)map.get(key));
      if (icbe.getExpression() != null && icbe.getExpression().getGroupName().equals(groupName) && groupLevel != 0) {
        exprCol.add(icbe.getExpression());
        resultSetExpressions.put(key,icbe);
      }
 else       if (groupLevel == 0 && icbe.getAggregatOns().size() == 0) {
        exprCol.add(icbe.getExpression());
        resultSetExpressions.put(key,icbe);
      }
 else       if (groupLevel != 0 && icbe.getAggregatOns().contains(groupName)) {
        exprCol.add(icbe.getExpression());
        resultSetExpressions.put(key,icbe);
      }
    }
  }
  prepareExpressions(exprCol,groupLevel,false,true,cx);
  String key=null;
  if (trans instanceof IGroupDefinition) {
    IGroupDefinition gd=(IGroupDefinition)trans;
    key=gd.getKeyColumn() != null ? gd.getKeyColumn() : gd.getKeyExpression();
  }
  this.exprManager.addBindingExpr(key,resultSetExpressions,groupLevel);
  Collection subQueries=trans.getSubqueries();
  Iterator subIt=subQueries.iterator();
  while (subIt.hasNext()) {
    ISubqueryDefinition subquery=(ISubqueryDefinition)subIt.next();
    PreparedSubquery pq=new PreparedSubquery(this.session,this.dataEngineContext,subquery,queryService,groupLevel,this.exprManager);
    subQueryMap.put(subquery.getName(),pq);
    subQueryDefnMap.put(subquery.getName(),new Object[]{subquery,new Integer(groupLevel)});
  }
}