Program: 78339
Project: 78339
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=-1;
  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;
  }
  boolean hideDetail=false;
  int hideGroupStartIndex=-1;
  do {
    rsetCursor++;
    int startGroup=rset.getStartingGroupLevel();
    ArrayList groupList=listing.getGroups();
    if (startGroup != NONE_GROUP) {
      groupIndex=startGroup - 1;
      if (groupIndex < 0) {
        groupIndex=0;
      }
      while (groupIndex < groupCount && (hideGroupStartIndex == -1 || groupIndex < hideGroupStartIndex)) {
        startGroupTOCEntry();
        startTOCEntry(null);
        accessGroupHeader(listing,groupIndex,outputEmitter);
        finishTOCEntry();
        groupIndex++;
        GroupDesign groupDesign=(GroupDesign)groupList.get(groupIndex - 1);
        if (groupDesign.getHideDetail() && hideGroupStartIndex == -1) {
          hideDetail=true;
          hideGroupStartIndex=groupIndex;
          break;
        }
      }
      clearDuplicateFlags(listing);
    }
    startGroupTOCEntry();
    if (!hideDetail) {
      accessDetail(listing,outputEmitter,rsIterator);
    }
    finishGroupTOCEntry();
    int endGroup=rset.getEndingGroupLevel();
    if (endGroup != NONE_GROUP) {
      endGroup=endGroup - 1;
      if (endGroup < 0) {
        endGroup=0;
      }
      if (hideGroupStartIndex == -1) {
        groupIndex=groupCount - 1;
      }
 else {
        groupIndex=hideGroupStartIndex - 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());
}

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=-1;
  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;
  }
  boolean hideDetail=false;
  int hideGroupStartIndex=-1;
  do {
    rsetCursor++;
    int startGroup=rset.getStartingGroupLevel();
    ArrayList groupList=listing.getGroups();
    if (startGroup != NONE_GROUP) {
      groupIndex=startGroup - 1;
      if (groupIndex < 0) {
        groupIndex=0;
      }
      while (groupIndex < groupCount && (hideGroupStartIndex == -1 || groupIndex < hideGroupStartIndex)) {
        startGroupTOCEntry();
        startTOCEntry(null);
        accessGroupHeader(listing,groupIndex,outputEmitter);
        finishTOCEntry();
        groupIndex++;
        GroupDesign groupDesign=(GroupDesign)groupList.get(groupIndex - 1);
        if (groupDesign.getHideDetail() && hideGroupStartIndex == -1) {
          hideDetail=true;
          hideGroupStartIndex=groupIndex;
          break;
        }
      }
      clearDuplicateFlags(listing);
    }
    startGroupTOCEntry();
    if (!hideDetail) {
      accessDetail(listing,outputEmitter,rsIterator);
    }
    finishGroupTOCEntry();
    int endGroup=rset.getEndingGroupLevel();
    if (endGroup != NONE_GROUP) {
      endGroup=endGroup - 1;
      if (endGroup < 0) {
        endGroup=0;
      }
      if (hideGroupStartIndex == -1) {
        groupIndex=groupCount - 1;
      }
 else {
        groupIndex=hideGroupStartIndex - 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) {
      startTOCEntry(null);
      accessFooter(listing,outputEmitter,rsIterator);
      finishTOCEntry();
    }
  }
 while (rset.next());
}