Program: 70691
Project: 70691
Buggy source:
private List buildRowArea(){
  List retValue=new ArrayList();
  CrosstabReportItemHandle handle=getCrosstabReportItemHandle();
  int count=handle.getDimensionCount(ICrosstabConstants.ROW_AXIS_TYPE);
  int measureCount=handle.getMeasureCount();
  int columnNumber=measureCount == 0 ? 1 : 2;
  if (!isVertical()) {
    columnNumber=1;
  }
  List measureHandleList=getMeasreViewHandleList();
  int rowNumber=0;
  if (count != 0) {
    rowNumber=addMesureHeader(retValue,0,ICrosstabConstants.ROW_AXIS_TYPE,measureHandleList);
  }
  if (rowNumber == 0) {
    rowNumber=1;
  }
  for (int i=count - 1; i >= 0; i--) {
    DimensionViewHandle dimensionHandle=handle.getDimension(ICrosstabConstants.ROW_AXIS_TYPE,i);
    int levelCount=dimensionHandle.getLevelCount();
    for (int j=levelCount - 1; j >= 0; j--) {
      LevelViewHandle levelHandle=dimensionHandle.getLevel(j);
      CrosstabCellHandle cellHandle=levelHandle.getCell();
      String type=j == 0 ? ICrosstabCellAdapterFactory.CELL_FIRST_LEVEL_HANDLE : ICrosstabCellAdapterFactory.CELL_LEVEL_HANDLE;
      CrosstabCellAdapter cellAdapter=factory.createCrosstabCellAdapter(type,cellHandle,1,rowNumber,columnNumber,-1,false);
      retValue.add(cellAdapter);
      map.put(levelHandle,Integer.valueOf(rowNumber));
      LevelViewHandle preLevelHandle=getPreviousLevelViewHandle(dimensionHandle,levelHandle);
      if (preLevelHandle != null && preLevelHandle.getAggregationHeader() != null) {
        List list=preLevelHandle.getAggregationMeasures();
        if (list.size() != 0) {
          int preMeasureCount=list.size();
          CrosstabCellHandle preCellHandle=preLevelHandle.getAggregationHeader();
          CrosstabCellAdapter preCellAdapter=factory.createCrosstabCellAdapter(ICrosstabCellAdapterFactory.CELL_SUB_TOTAL,preCellHandle,rowNumber + 1,isVertical() ? preMeasureCount : 1,columnNumber,columnNumber - (isVertical() ? 1 : 0),false);
          retValue.add(preCellAdapter);
          int addCount=addMesureHeader(retValue,rowNumber,ICrosstabConstants.ROW_AXIS_TYPE,list);
          rowNumber=rowNumber + (addCount == 0 ? 1 : addCount);
        }
      }
      if (j != 0 || i != 0) {
        columnNumber=columnNumber + 1;
      }
    }
  }
  CrosstabCellHandle grandCell=handle.getGrandTotal(ICrosstabConstants.ROW_AXIS_TYPE);
  if (grandCell != null && !retValue.isEmpty()) {
    List list=handle.getAggregationMeasures(ICrosstabConstants.ROW_AXIS_TYPE);
    int size=list.size();
    if (size > 0) {
      CrosstabCellAdapter grandCellAdapter=factory.createCrosstabCellAdapter(ICrosstabCellAdapterFactory.CELL_GRAND_TOTAL,grandCell,rowNumber + 1,isVertical() ? size : 1,columnNumber,columnNumber - (isVertical() ? 1 : 0),false);
      retValue.add(grandCellAdapter);
      int addCount=addMesureHeader(retValue,rowNumber,ICrosstabConstants.ROW_AXIS_TYPE,list);
      rowNumber=rowNumber + (addCount == 0 ? 1 : addCount);
    }
  }
  if (retValue.isEmpty()) {
    CrosstabCellAdapter columnVirtual=factory.createCrosstabCellAdapter(ICrosstabCellAdapterFactory.CELL_ROW_VIRTUAL,null,1,-1,1,-1,false);
    retValue.add(columnVirtual);
    columnNumber=1;
    rowNumber=1;
  }
  map.put(ROWAREA_COLUMN,Integer.valueOf(columnNumber));
  map.put(ROWAREA_ROW,Integer.valueOf(rowNumber));
  covertColumnNumber(columnNumber,retValue);
  return retValue;
}

Fixed version (ground truth):
private List buildRowArea(){
  List retValue=new ArrayList();
  CrosstabReportItemHandle handle=getCrosstabReportItemHandle();
  int count=handle.getDimensionCount(ICrosstabConstants.ROW_AXIS_TYPE);
  int measureCount=handle.getMeasureCount();
  int columnNumber=measureCount == 0 ? 1 : 2;
  if (!isVertical() || isHideHeader()) {
    columnNumber=1;
  }
  List measureHandleList=getMeasreViewHandleList();
  int rowNumber=0;
  if (count != 0) {
    rowNumber=addMesureHeader(retValue,0,ICrosstabConstants.ROW_AXIS_TYPE,measureHandleList);
  }
  if (rowNumber == 0) {
    rowNumber=1;
  }
  for (int i=count - 1; i >= 0; i--) {
    DimensionViewHandle dimensionHandle=handle.getDimension(ICrosstabConstants.ROW_AXIS_TYPE,i);
    int levelCount=dimensionHandle.getLevelCount();
    for (int j=levelCount - 1; j >= 0; j--) {
      LevelViewHandle levelHandle=dimensionHandle.getLevel(j);
      CrosstabCellHandle cellHandle=levelHandle.getCell();
      String type=j == 0 ? ICrosstabCellAdapterFactory.CELL_FIRST_LEVEL_HANDLE : ICrosstabCellAdapterFactory.CELL_LEVEL_HANDLE;
      CrosstabCellAdapter cellAdapter=factory.createCrosstabCellAdapter(type,cellHandle,1,rowNumber,columnNumber,-1,false);
      retValue.add(cellAdapter);
      map.put(levelHandle,Integer.valueOf(rowNumber));
      LevelViewHandle preLevelHandle=getPreviousLevelViewHandle(dimensionHandle,levelHandle);
      if (preLevelHandle != null && preLevelHandle.getAggregationHeader() != null) {
        List list=preLevelHandle.getAggregationMeasures();
        if (list.size() != 0) {
          int preMeasureCount=list.size();
          CrosstabCellHandle preCellHandle=preLevelHandle.getAggregationHeader();
          CrosstabCellAdapter preCellAdapter=factory.createCrosstabCellAdapter(ICrosstabCellAdapterFactory.CELL_SUB_TOTAL,preCellHandle,rowNumber + 1,isVertical() ? preMeasureCount : 1,columnNumber,columnNumber - (isVertical() && !isHideHeader() ? 1 : 0),false);
          retValue.add(preCellAdapter);
          int addCount=addMesureHeader(retValue,rowNumber,ICrosstabConstants.ROW_AXIS_TYPE,list);
          rowNumber=rowNumber + (addCount == 0 ? 1 : addCount);
        }
      }
      if (j != 0 || i != 0) {
        columnNumber=columnNumber + 1;
      }
    }
  }
  CrosstabCellHandle grandCell=handle.getGrandTotal(ICrosstabConstants.ROW_AXIS_TYPE);
  if (grandCell != null && !retValue.isEmpty()) {
    List list=handle.getAggregationMeasures(ICrosstabConstants.ROW_AXIS_TYPE);
    int size=list.size();
    if (size > 0) {
      CrosstabCellAdapter grandCellAdapter=factory.createCrosstabCellAdapter(ICrosstabCellAdapterFactory.CELL_GRAND_TOTAL,grandCell,rowNumber + 1,isVertical() ? size : 1,columnNumber,columnNumber - (isVertical() && !isHideHeader() ? 1 : 0),false);
      retValue.add(grandCellAdapter);
      int addCount=addMesureHeader(retValue,rowNumber,ICrosstabConstants.ROW_AXIS_TYPE,list);
      rowNumber=rowNumber + (addCount == 0 ? 1 : addCount);
    }
  }
  if (retValue.isEmpty()) {
    CrosstabCellAdapter columnVirtual=factory.createCrosstabCellAdapter(ICrosstabCellAdapterFactory.CELL_ROW_VIRTUAL,null,1,-1,1,-1,false);
    retValue.add(columnVirtual);
    columnNumber=1;
    rowNumber=1;
  }
  map.put(ROWAREA_COLUMN,Integer.valueOf(columnNumber));
  map.put(ROWAREA_ROW,Integer.valueOf(rowNumber));
  covertColumnNumber(columnNumber,retValue);
  return retValue;
}