Program: 78500
Project: 78500
Buggy source:
/** 
 * access the query and create the contents. the execution process is: <li> the cursor is at the begin of result set. <li> call listing's onStart event <li> create the header <li> for each row: <ul> <li> call onRow event. <li> if the row start some groups, create the group header for that group. <li> create the detail row. <li> if the row end some groups, create the group footer for that group. </ul> <li> create the footer. <li> call the onFinish event.
 */
protected void accessQuery(ReportItemDesign design,IContentEmitter emitter){
  ListingDesign listing=(ListingDesign)design;
  rsetCursor=-1;
  outputEmitter=emitter;
  int groupCount=listing.getGroupCount();
  int NONE_GROUP=groupCount + 1;
  int groupIndex;
  int pageBreakInterval=listing.getPageBreakInterval();
  if (rset == null || rsetEmpty == true) {
    startTOCEntry(null);
    accessHeader(listing,outputEmitter,null);
    finishTOCEntry();
    startTOCEntry(null);
    accessFooter(listing,outputEmitter,null);
    finishTOCEntry();
    return;
  }
  IResultIterator rsIterator=((DteResultSet)rset).getResultIterator();
  IBaseQueryDefinition query=listing.getQuery();
  Collection rowExpressions=(query == null ? null : query.getRowExpressions());
  Collection beforeExpressions=(query == null ? null : query.getBeforeExpressions());
  Collection afterExpressions=(query == null ? null : query.getAfterExpressions());
  IRowData rowData=new RowData(rsIterator,rowExpressions);
  IRowData headerData=new RowData(rsIterator,beforeExpressions);
  IRowData footerData=new RowData(rsIterator,afterExpressions);
  startTOCEntry(null);
  accessHeader(listing,outputEmitter,headerData);
  finishTOCEntry();
  if (groupCount == 0) {
    do {
      rsetCursor++;
      startTOCEntry(null);
      accessDetail(listing,outputEmitter,rowData);
      finishTOCEntry();
      if (pageBreakInterval > 0) {
        if ((rsetCursor + 1) % pageBreakInterval == 0) {
          needPageBreak=true;
        }
      }
      if (rset.getEndingGroupLevel() == 0) {
        needPageBreak=false;
        startTOCEntry(null);
        accessFooter(listing,outputEmitter,footerData);
        finishTOCEntry();
      }
    }
 while (rset.next());
    return;
  }
  do {
    rsetCursor++;
    int startGroup=rset.getStartingGroupLevel();
    if (startGroup != NONE_GROUP) {
      groupIndex=startGroup - 1;
      if (groupIndex < 0) {
        groupIndex=0;
      }
      while (groupIndex < groupCount) {
        startGroupTOCEntry();
        startTOCEntry(null);
        accessGroupHeader(listing,groupIndex,outputEmitter);
        finishTOCEntry();
        groupIndex++;
      }
    }
    startGroupTOCEntry();
    accessDetail(listing,outputEmitter,rowData);
    finishGroupTOCEntry();
    int endGroup=rset.getEndingGroupLevel();
    if (endGroup != NONE_GROUP) {
      endGroup=endGroup - 1;
      if (endGroup < 0) {
        endGroup=0;
      }
      groupIndex=groupCount - 1;
      while (groupIndex >= endGroup) {
        startTOCEntry(null);
        accessGroupFooter(listing,groupIndex,outputEmitter);
        finishTOCEntry();
        finishGroupTOCEntry();
        groupIndex--;
      }
    }
    if (pageBreakInterval > 0) {
      if ((rsetCursor + 1) % pageBreakInterval == 0) {
        needPageBreak=true;
      }
    }
    if (rset.getEndingGroupLevel() == 0) {
      needPageBreak=false;
      startTOCEntry(null);
      accessFooter(listing,outputEmitter,footerData);
      finishTOCEntry();
    }
  }
 while (rset.next());
}

Fixed version (ground truth):
/** 
 * access the query and create the contents. the execution process is: <li> the cursor is at the begin of result set. <li> call listing's onStart event <li> create the header <li> for each row: <ul> <li> call onRow event. <li> if the row start some groups, create the group header for that group. <li> create the detail row. <li> if the row end some groups, create the group footer for that group. </ul> <li> create the footer. <li> call the onFinish event.
 */
protected void accessQuery(ReportItemDesign design,IContentEmitter emitter){
  ListingDesign listing=(ListingDesign)design;
  rsetCursor=-1;
  outputEmitter=emitter;
  int groupCount=listing.getGroupCount();
  int NONE_GROUP=groupCount + 1;
  int groupIndex;
  int pageBreakInterval=listing.getPageBreakInterval();
  if (rset == null || rsetEmpty == true) {
    startTOCEntry(null);
    accessHeader(listing,outputEmitter,null);
    finishTOCEntry();
    startTOCEntry(null);
    accessFooter(listing,outputEmitter,null);
    finishTOCEntry();
    return;
  }
  IResultIterator rsIterator=((DteResultSet)rset).getResultIterator();
  startTOCEntry(null);
  accessHeader(listing,outputEmitter,rsIterator);
  finishTOCEntry();
  if (groupCount == 0) {
    do {
      rsetCursor++;
      startTOCEntry(null);
      accessDetail(listing,outputEmitter,rsIterator);
      finishTOCEntry();
      if (pageBreakInterval > 0) {
        if ((rsetCursor + 1) % pageBreakInterval == 0) {
          needPageBreak=true;
        }
      }
      if (rset.getEndingGroupLevel() == 0) {
        needPageBreak=false;
        startTOCEntry(null);
        accessFooter(listing,outputEmitter,rsIterator);
        finishTOCEntry();
      }
    }
 while (rset.next());
    return;
  }
  do {
    rsetCursor++;
    int startGroup=rset.getStartingGroupLevel();
    if (startGroup != NONE_GROUP) {
      groupIndex=startGroup - 1;
      if (groupIndex < 0) {
        groupIndex=0;
      }
      while (groupIndex < groupCount) {
        startGroupTOCEntry();
        startTOCEntry(null);
        accessGroupHeader(listing,groupIndex,outputEmitter);
        finishTOCEntry();
        groupIndex++;
      }
    }
    startGroupTOCEntry();
    accessDetail(listing,outputEmitter,rsIterator);
    finishGroupTOCEntry();
    int endGroup=rset.getEndingGroupLevel();
    if (endGroup != NONE_GROUP) {
      endGroup=endGroup - 1;
      if (endGroup < 0) {
        endGroup=0;
      }
      groupIndex=groupCount - 1;
      while (groupIndex >= endGroup) {
        startTOCEntry(null);
        accessGroupFooter(listing,groupIndex,outputEmitter);
        finishTOCEntry();
        finishGroupTOCEntry();
        groupIndex--;
      }
    }
    if (pageBreakInterval > 0) {
      if ((rsetCursor + 1) % pageBreakInterval == 0) {
        needPageBreak=true;
      }
    }
    if (rset.getEndingGroupLevel() == 0) {
      needPageBreak=false;
      startTOCEntry(null);
      accessFooter(listing,outputEmitter,rsIterator);
      finishTOCEntry();
    }
  }
 while (rset.next());
}