Program: 69403
Project: 69403
Buggy source:
private void advance() throws OLAPException {
switch (currentState) {
case STATE_INIT:
case STATE_ROW_EDGE:
    if (rowGroups.size() > 0) {
      for (int i=groupIndex; i < rowGroups.size(); i++) {
        EdgeGroup group=(EdgeGroup)rowGroups.get(i);
        groupIndex++;
        dimensionIndex=group.dimensionIndex;
        levelIndex=group.levelIndex;
        currentState=STATE_ROW_EDGE;
        return;
      }
    }
  if (mCount > 0 && isVerticalMeasure && !isHideMeasureHeader) {
    for (int i=0; i < mCount; i++) {
      MeasureViewHandle mv=crosstabItem.getMeasure(i);
      if (mv.getHeader() != null) {
        currentState=STATE_MEASURE_HEADER;
        return;
      }
    }
  }
case STATE_MEASURE_HEADER:
inProcessingGrandTotalBefore=columnGroups.size() > 0 && columnEdgeCursor != null && crosstabItem.getGrandTotal(COLUMN_AXIS_TYPE) != null && GRAND_TOTAL_LOCATION_BEFORE.equals(crosstabItem.getCrosstabView(COLUMN_AXIS_TYPE).getGrandTotalLocation());
case STATE_PENDING_CHECK_COLUMN_EDGE:
if (!inProcessingGrandTotalBefore && columnGroups.size() > 0 && columnEdgeCursor != null) {
columnDimensionCursors=columnEdgeCursor.getDimensionCursor();
columnEdgeCursor.beforeFirst();
hasNext=columnEdgeCursor.next();
columnProcessed=false;
groupIndex=0;
measureIndex=-1;
tmpStartGroupIndex=0;
tmpEndGroupIndex=lastColumnGroupIndex;
}
case STATE_COLUMN_TOTAL_BEFORE:
case STATE_COLUMN_TOTAL_AFTER:
case STATE_COLUMN_EDGE:
if (!inProcessingGrandTotalBefore && columnGroups.size() > 0 && columnEdgeCursor != null) {
while (hasNext) {
if (mCount > 0 || !IGNORE_TOTAL_COLUMN_WITHOUT_MEASURE) {
  for (int i=tmpStartGroupIndex; i < columnGroups.size(); i++) {
    EdgeGroup group=(EdgeGroup)columnGroups.get(i);
    if (!GroupUtil.isLeafGroup(columnDimensionCursors,i)) {
      DimensionCursor dc=(DimensionCursor)columnDimensionCursors.get(i);
      if (dc.getEdgeStart() == columnEdgeCursor.getPosition()) {
        LevelViewHandle lv=crosstabItem.getDimension(COLUMN_AXIS_TYPE,group.dimensionIndex).getLevel(group.levelIndex);
        if (lv.getAggregationHeader() != null && AGGREGATION_HEADER_LOCATION_BEFORE.equals(lv.getAggregationHeaderLocation())) {
          if (mCount > 0 && !isVerticalMeasure) {
            for (int m=measureIndex + 1; m < mCount; m++) {
              if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,group.dimensionIndex,group.levelIndex,m)) {
                tmpStartGroupIndex=i;
                dimensionIndex=group.dimensionIndex;
                levelIndex=group.levelIndex;
                measureIndex=m;
                currentState=STATE_COLUMN_TOTAL_BEFORE;
                return;
              }
            }
            measureIndex=-1;
          }
 else           if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,group.dimensionIndex,group.levelIndex,-1)) {
            tmpStartGroupIndex=i + 1;
            dimensionIndex=group.dimensionIndex;
            levelIndex=group.levelIndex;
            currentState=STATE_COLUMN_TOTAL_BEFORE;
            return;
          }
        }
      }
    }
  }
  tmpStartGroupIndex=columnGroups.size();
}
if (currentState != STATE_COLUMN_EDGE && currentState != STATE_COLUMN_TOTAL_AFTER) {
  measureIndex=-1;
}
if (!columnProcessed) {
  if (mCount > 0 && !isVerticalMeasure) {
    for (int m=measureIndex + 1; m < mCount; m++) {
      measureIndex=m;
      currentState=STATE_COLUMN_EDGE;
      return;
    }
  }
 else   if (measureIndex == -1) {
    measureIndex--;
    currentState=STATE_COLUMN_EDGE;
    return;
  }
  columnProcessed=true;
}
if (mCount > 0 || !IGNORE_TOTAL_COLUMN_WITHOUT_MEASURE) {
  if (currentState != STATE_COLUMN_TOTAL_AFTER) {
    measureIndex=-1;
  }
  for (int i=tmpEndGroupIndex; i >= 0; i--) {
    EdgeGroup group=(EdgeGroup)columnGroups.get(i);
    if (!GroupUtil.isLeafGroup(columnDimensionCursors,i)) {
      DimensionCursor dc=(DimensionCursor)columnDimensionCursors.get(i);
      if (dc.getEdgeEnd() == columnEdgeCursor.getPosition()) {
        LevelViewHandle lv=crosstabItem.getDimension(COLUMN_AXIS_TYPE,group.dimensionIndex).getLevel(group.levelIndex);
        if (lv.getAggregationHeader() != null && AGGREGATION_HEADER_LOCATION_AFTER.equals(lv.getAggregationHeaderLocation())) {
          if (mCount > 0 && !isVerticalMeasure) {
            for (int m=measureIndex + 1; m < mCount; m++) {
              if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,group.dimensionIndex,group.levelIndex,m)) {
                tmpEndGroupIndex=i;
                dimensionIndex=group.dimensionIndex;
                levelIndex=group.levelIndex;
                measureIndex=m;
                currentState=STATE_COLUMN_TOTAL_AFTER;
                return;
              }
            }
            measureIndex=-1;
          }
 else           if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,group.dimensionIndex,group.levelIndex,-1)) {
            tmpEndGroupIndex=i - 1;
            dimensionIndex=group.dimensionIndex;
            levelIndex=group.levelIndex;
            currentState=STATE_COLUMN_TOTAL_AFTER;
            return;
          }
        }
      }
    }
  }
}
hasNext=columnEdgeCursor.next();
columnProcessed=false;
tmpStartGroupIndex=0;
tmpEndGroupIndex=lastColumnGroupIndex;
measureIndex=-1;
}
if (crosstabItem.getGrandTotal(COLUMN_AXIS_TYPE) != null && GRAND_TOTAL_LOCATION_BEFORE.equals(crosstabItem.getCrosstabView(COLUMN_AXIS_TYPE).getGrandTotalLocation())) {
currentState=STATE_END;
return;
}
}
measureIndex=-1;
case STATE_GRAND_TOTAL:
if (columnGroups.size() > 0 && columnEdgeCursor != null) {
if (crosstabItem.getGrandTotal(COLUMN_AXIS_TYPE) != null) {
if (mCount > 0 || !IGNORE_TOTAL_COLUMN_WITHOUT_MEASURE) {
if (mCount > 0 && !isVerticalMeasure) {
for (int i=measureIndex + 1; i < mCount; i++) {
  if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,-1,-1,i)) {
    measureIndex=i;
    currentState=STATE_GRAND_TOTAL;
    return;
  }
}
}
 else if (currentState != STATE_GRAND_TOTAL) {
if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,-1,-1,-1)) {
  currentState=STATE_GRAND_TOTAL;
  return;
}
}
}
if (inProcessingGrandTotalBefore) {
inProcessingGrandTotalBefore=false;
currentState=STATE_PENDING_CHECK_COLUMN_EDGE;
return;
}
}
currentState=STATE_END;
return;
}
case STATE_MEASURE:
if (!isVerticalMeasure) {
for (int i=measureIndex + 1; i < mCount; i++) {
measureIndex=i;
currentState=STATE_MEASURE;
return;
}
}
 else if (measureIndex == -1) {
measureIndex--;
currentState=STATE_MEASURE;
return;
}
currentState=STATE_END;
return;
}
}

Fixed version (ground truth):
private void advance() throws OLAPException {
switch (currentState) {
case STATE_INIT:
case STATE_ROW_EDGE:
    if (rowGroups.size() > 0) {
      for (int i=groupIndex; i < rowGroups.size(); i++) {
        EdgeGroup group=(EdgeGroup)rowGroups.get(i);
        groupIndex++;
        dimensionIndex=group.dimensionIndex;
        levelIndex=group.levelIndex;
        currentState=STATE_ROW_EDGE;
        return;
      }
    }
  if (mCount > 0 && isVerticalMeasure && !isHideMeasureHeader) {
    for (int i=0; i < mCount; i++) {
      MeasureViewHandle mv=crosstabItem.getMeasure(i);
      if (mv.getHeader() != null) {
        currentState=STATE_MEASURE_HEADER;
        return;
      }
    }
  }
case STATE_MEASURE_HEADER:
inProcessingGrandTotalBefore=columnGroups.size() > 0 && columnEdgeCursor != null && crosstabItem.getGrandTotal(COLUMN_AXIS_TYPE) != null && GRAND_TOTAL_LOCATION_BEFORE.equals(crosstabItem.getCrosstabView(COLUMN_AXIS_TYPE).getGrandTotalLocation());
case STATE_PENDING_CHECK_COLUMN_EDGE:
if (!inProcessingGrandTotalBefore && columnGroups.size() > 0 && columnEdgeCursor != null) {
columnDimensionCursors=columnEdgeCursor.getDimensionCursor();
columnEdgeCursor.beforeFirst();
hasNext=columnEdgeCursor.next();
columnProcessed=false;
groupIndex=0;
measureIndex=-1;
tmpStartGroupIndex=0;
tmpEndGroupIndex=lastColumnGroupIndex;
}
case STATE_COLUMN_TOTAL_BEFORE:
case STATE_COLUMN_TOTAL_AFTER:
case STATE_COLUMN_EDGE:
if (!inProcessingGrandTotalBefore && columnGroups.size() > 0 && columnEdgeCursor != null) {
while (hasNext) {
if (mCount > 0 || !IGNORE_TOTAL_COLUMN_WITHOUT_MEASURE) {
  for (int i=tmpStartGroupIndex; i < columnGroups.size(); i++) {
    EdgeGroup group=(EdgeGroup)columnGroups.get(i);
    if (!GroupUtil.isLeafGroup(columnDimensionCursors,i)) {
      DimensionCursor dc=(DimensionCursor)columnDimensionCursors.get(i);
      if (dc.getEdgeStart() == columnEdgeCursor.getPosition()) {
        LevelViewHandle lv=crosstabItem.getDimension(COLUMN_AXIS_TYPE,group.dimensionIndex).getLevel(group.levelIndex);
        if (lv.getAggregationHeader() != null && AGGREGATION_HEADER_LOCATION_BEFORE.equals(lv.getAggregationHeaderLocation())) {
          if (mCount > 0 && !isVerticalMeasure) {
            for (int m=measureIndex + 1; m < mCount; m++) {
              if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,group.dimensionIndex,group.levelIndex,m)) {
                tmpStartGroupIndex=i;
                dimensionIndex=group.dimensionIndex;
                levelIndex=group.levelIndex;
                measureIndex=m;
                currentState=STATE_COLUMN_TOTAL_BEFORE;
                return;
              }
            }
            measureIndex=-1;
          }
 else           if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,group.dimensionIndex,group.levelIndex,-1)) {
            tmpStartGroupIndex=i + 1;
            dimensionIndex=group.dimensionIndex;
            levelIndex=group.levelIndex;
            currentState=STATE_COLUMN_TOTAL_BEFORE;
            return;
          }
        }
      }
    }
  }
  tmpStartGroupIndex=columnGroups.size();
}
if (currentState != STATE_COLUMN_EDGE && currentState != STATE_COLUMN_TOTAL_AFTER) {
  measureIndex=-1;
}
if (!columnProcessed) {
  if (mCount > 0 && !isVerticalMeasure) {
    for (int m=measureIndex + 1; m < mCount; m++) {
      measureIndex=m;
      currentState=STATE_COLUMN_EDGE;
      return;
    }
  }
 else   if (measureIndex == -1) {
    measureIndex--;
    currentState=STATE_COLUMN_EDGE;
    return;
  }
  columnProcessed=true;
}
if (mCount > 0 || !IGNORE_TOTAL_COLUMN_WITHOUT_MEASURE) {
  if (currentState != STATE_COLUMN_TOTAL_AFTER) {
    measureIndex=-1;
  }
  for (int i=tmpEndGroupIndex; i >= 0; i--) {
    EdgeGroup group=(EdgeGroup)columnGroups.get(i);
    if (!GroupUtil.isLeafGroup(columnDimensionCursors,i)) {
      DimensionCursor dc=(DimensionCursor)columnDimensionCursors.get(i);
      if (dc.getEdgeEnd() == columnEdgeCursor.getPosition()) {
        LevelViewHandle lv=crosstabItem.getDimension(COLUMN_AXIS_TYPE,group.dimensionIndex).getLevel(group.levelIndex);
        if (lv.getAggregationHeader() != null && AGGREGATION_HEADER_LOCATION_AFTER.equals(lv.getAggregationHeaderLocation())) {
          if (mCount > 0 && !isVerticalMeasure) {
            for (int m=measureIndex + 1; m < mCount; m++) {
              if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,group.dimensionIndex,group.levelIndex,m)) {
                tmpEndGroupIndex=i;
                dimensionIndex=group.dimensionIndex;
                levelIndex=group.levelIndex;
                measureIndex=m;
                currentState=STATE_COLUMN_TOTAL_AFTER;
                return;
              }
            }
            measureIndex=-1;
          }
 else           if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,group.dimensionIndex,group.levelIndex,-1)) {
            tmpEndGroupIndex=i - 1;
            dimensionIndex=group.dimensionIndex;
            levelIndex=group.levelIndex;
            currentState=STATE_COLUMN_TOTAL_AFTER;
            return;
          }
        }
      }
    }
  }
}
hasNext=columnEdgeCursor.next();
columnProcessed=false;
tmpStartGroupIndex=0;
tmpEndGroupIndex=lastColumnGroupIndex;
measureIndex=-1;
}
if (crosstabItem.getGrandTotal(COLUMN_AXIS_TYPE) != null && GRAND_TOTAL_LOCATION_BEFORE.equals(crosstabItem.getCrosstabView(COLUMN_AXIS_TYPE).getGrandTotalLocation())) {
currentState=STATE_END;
return;
}
}
measureIndex=-1;
case STATE_GRAND_TOTAL:
if (columnGroups.size() > 0 && columnEdgeCursor != null) {
if (crosstabItem.getGrandTotal(COLUMN_AXIS_TYPE) != null) {
if (mCount > 0 || !IGNORE_TOTAL_COLUMN_WITHOUT_MEASURE) {
if (mCount > 0 && !isVerticalMeasure) {
for (int i=measureIndex + 1; i < mCount; i++) {
  if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,-1,-1,i)) {
    measureIndex=i;
    currentState=STATE_GRAND_TOTAL;
    return;
  }
}
}
 else if (currentState != STATE_GRAND_TOTAL) {
if (GroupUtil.hasTotalContent(crosstabItem,COLUMN_AXIS_TYPE,-1,-1,-1)) {
  currentState=STATE_GRAND_TOTAL;
  return;
}
}
}
if (inProcessingGrandTotalBefore) {
inProcessingGrandTotalBefore=false;
currentState=STATE_PENDING_CHECK_COLUMN_EDGE;
return;
}
}
currentState=STATE_END;
return;
}
case STATE_MEASURE:
if (!isVerticalMeasure) {
for (int i=measureIndex + 1; i < mCount; i++) {
measureIndex=i;
currentState=STATE_MEASURE;
return;
}
}
 else if (measureIndex == -1 && mCount > 0) {
measureIndex--;
currentState=STATE_MEASURE;
return;
}
currentState=STATE_END;
return;
}
}