Program: 74202
Project: 74202
Buggy source:
/** 
 * Locates the cell which controls the row height for given cell
 * @param crosstabItem
 * @param cell
 * @return
 */
public static CrosstabCellHandle locateRowHeightCell(CrosstabReportItemHandle crosstabItem,CrosstabCellHandle cell){
  if (crosstabItem != null && cell != null && cell.getCrosstab() == crosstabItem) {
    boolean isMeasureHorizontal=MEASURE_DIRECTION_HORIZONTAL.equals(crosstabItem.getMeasureDirection());
    if (cell instanceof AggregationCellHandle) {
      AggregationCellHandle aggCell=(AggregationCellHandle)cell;
      MeasureViewHandle mv=null;
      if (IMeasureViewConstants.DETAIL_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
        if (!isMeasureHorizontal) {
          return ((MeasureViewHandle)cell.getContainer()).getCell();
        }
 else {
          return crosstabItem.getMeasure(0).getCell();
        }
      }
      if (!isMeasureHorizontal) {
        mv=(MeasureViewHandle)aggCell.getContainer();
      }
 else {
        mv=crosstabItem.getMeasure(0);
      }
      String rowDimension=aggCell.getDimensionName(ROW_AXIS_TYPE);
      String rowLevel=aggCell.getLevelName(ROW_AXIS_TYPE);
      LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
      DimensionViewHandle rowDimHandle=(DimensionViewHandle)rowLevelHandle.getContainer();
      if (rowLevelHandle.getCubeLevelName().equals(rowLevel) && rowDimHandle.getCubeDimensionName().equals(rowDimension)) {
        return mv.getCell();
      }
      String colDimension=null;
      String colLevel=null;
      LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
      if (colLevelHandle != null) {
        colDimension=((DimensionViewHandle)colLevelHandle.getContainer()).getCubeDimensionName();
        colLevel=colLevelHandle.getCubeLevelName();
      }
      return mv.getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
    }
 else     if (cell.getContainer() instanceof MeasureViewHandle) {
      if (!isMeasureHorizontal) {
        return ((MeasureViewHandle)cell.getContainer()).getCell();
      }
 else       if (IMeasureViewConstants.HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
        for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
          MeasureViewHandle mv=crosstabItem.getMeasure(i);
          if (mv.getHeader() != null) {
            return mv.getHeader();
          }
        }
      }
 else {
        return crosstabItem.getMeasure(0).getCell();
      }
    }
 else     if (cell.getContainer() instanceof LevelViewHandle) {
      LevelViewHandle lv=(LevelViewHandle)cell.getContainer();
      boolean isRowLevl=ICrosstabReportItemConstants.ROWS_PROP.equals(lv.getContainer().getContainer().getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName());
      if (!isRowLevl) {
        if (ILevelViewConstants.AGGREGATION_HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
          return getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE).getCell();
        }
        return cell;
      }
      if (crosstabItem.getMeasureCount() == 0) {
        if (ILevelViewConstants.AGGREGATION_HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
          return cell;
        }
        return getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE).getCell();
      }
      if (ILevelViewConstants.AGGREGATION_HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
        String colDimension=null;
        String colLevel=null;
        String rowDimension=((DimensionViewHandle)lv.getContainer()).getCubeDimensionName();
        String rowLevel=lv.getCubeLevelName();
        LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
        if (colLevelHandle != null) {
          colDimension=((DimensionViewHandle)colLevelHandle.getContainer()).getCubeDimensionName();
          colLevel=colLevelHandle.getCubeLevelName();
        }
        if (isMeasureHorizontal) {
          return crosstabItem.getMeasure(0).getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
        }
 else {
          for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
            CrosstabCellHandle aggCell=crosstabItem.getMeasure(i).getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
            if (aggCell != null) {
              return aggCell;
            }
          }
        }
      }
      return crosstabItem.getMeasure(0).getCell();
    }
 else     if (cell.getContainer() instanceof CrosstabViewHandle) {
      boolean isRowGrandTotal=ICrosstabReportItemConstants.ROWS_PROP.equals(cell.getContainer().getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName());
      if (!isRowGrandTotal) {
        LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
        if (colLevelHandle != null) {
          return colLevelHandle.getCell();
        }
        return cell;
      }
      if (crosstabItem.getMeasureCount() == 0) {
        return cell;
      }
      String colDimension=null;
      String colLevel=null;
      LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
      if (colLevelHandle != null) {
        colDimension=((DimensionViewHandle)colLevelHandle.getContainer()).getCubeDimensionName();
        colLevel=colLevelHandle.getCubeLevelName();
      }
      if (isMeasureHorizontal) {
        return crosstabItem.getMeasure(0).getAggregationCell(null,null,colDimension,colLevel);
      }
 else {
        for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
          CrosstabCellHandle aggCell=crosstabItem.getMeasure(i).getAggregationCell(null,null,colDimension,colLevel);
          if (aggCell != null) {
            return aggCell;
          }
        }
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Locates the cell which controls the row height for given cell
 * @param crosstabItem
 * @param cell
 * @return
 */
public static CrosstabCellHandle locateRowHeightCell(CrosstabReportItemHandle crosstabItem,CrosstabCellHandle cell){
  if (crosstabItem != null && cell != null && cell.getCrosstab() == crosstabItem) {
    boolean isMeasureHorizontal=MEASURE_DIRECTION_HORIZONTAL.equals(crosstabItem.getMeasureDirection());
    if (cell instanceof AggregationCellHandle) {
      AggregationCellHandle aggCell=(AggregationCellHandle)cell;
      MeasureViewHandle mv=null;
      if (IMeasureViewConstants.DETAIL_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
        if (!isMeasureHorizontal) {
          return ((MeasureViewHandle)cell.getContainer()).getCell();
        }
 else {
          return crosstabItem.getMeasure(0).getCell();
        }
      }
      if (!isMeasureHorizontal) {
        mv=(MeasureViewHandle)aggCell.getContainer();
      }
 else {
        mv=crosstabItem.getMeasure(0);
      }
      String rowDimension=aggCell.getDimensionName(ROW_AXIS_TYPE);
      String rowLevel=aggCell.getLevelName(ROW_AXIS_TYPE);
      LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
      DimensionViewHandle rowDimHandle=(DimensionViewHandle)rowLevelHandle.getContainer();
      if (rowLevelHandle.getCubeLevelName().equals(rowLevel) && rowDimHandle.getCubeDimensionName().equals(rowDimension)) {
        return mv.getCell();
      }
      String colDimension=null;
      String colLevel=null;
      LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
      if (colLevelHandle != null) {
        colDimension=((DimensionViewHandle)colLevelHandle.getContainer()).getCubeDimensionName();
        colLevel=colLevelHandle.getCubeLevelName();
      }
      return mv.getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
    }
 else     if (cell.getContainer() instanceof MeasureViewHandle) {
      if (!isMeasureHorizontal) {
        return ((MeasureViewHandle)cell.getContainer()).getCell();
      }
 else       if (IMeasureViewConstants.HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
        for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
          MeasureViewHandle mv=crosstabItem.getMeasure(i);
          if (mv.getHeader() != null) {
            return mv.getHeader();
          }
        }
      }
 else {
        return crosstabItem.getMeasure(0).getCell();
      }
    }
 else     if (cell.getContainer() instanceof LevelViewHandle) {
      LevelViewHandle lv=(LevelViewHandle)cell.getContainer();
      boolean isRowLevl=ICrosstabReportItemConstants.ROWS_PROP.equals(lv.getContainer().getContainer().getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName());
      if (!isRowLevl) {
        if (ILevelViewConstants.AGGREGATION_HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
          return getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE).getCell();
        }
        return cell;
      }
      if (crosstabItem.getMeasureCount() == 0) {
        if (ILevelViewConstants.AGGREGATION_HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
          return cell;
        }
        return getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE).getCell();
      }
      if (ILevelViewConstants.AGGREGATION_HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
        String colDimension=null;
        String colLevel=null;
        String rowDimension=((DimensionViewHandle)lv.getContainer()).getCubeDimensionName();
        String rowLevel=lv.getCubeLevelName();
        LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
        if (colLevelHandle != null) {
          colDimension=((DimensionViewHandle)colLevelHandle.getContainer()).getCubeDimensionName();
          colLevel=colLevelHandle.getCubeLevelName();
        }
        if (isMeasureHorizontal) {
          return crosstabItem.getMeasure(0).getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
        }
 else {
          for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
            CrosstabCellHandle aggCell=crosstabItem.getMeasure(i).getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
            if (aggCell != null) {
              return aggCell;
            }
          }
        }
      }
      return crosstabItem.getMeasure(0).getCell();
    }
 else     if (cell.getContainer() instanceof CrosstabViewHandle) {
      boolean isRowGrandTotal=ICrosstabReportItemConstants.ROWS_PROP.equals(cell.getContainer().getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName());
      if (!isRowGrandTotal) {
        LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
        if (colLevelHandle != null) {
          return colLevelHandle.getCell();
        }
        return cell;
      }
      if (crosstabItem.getMeasureCount() == 0) {
        return cell;
      }
      String colDimension=null;
      String colLevel=null;
      LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
      if (colLevelHandle != null) {
        colDimension=((DimensionViewHandle)colLevelHandle.getContainer()).getCubeDimensionName();
        colLevel=colLevelHandle.getCubeLevelName();
      }
      if (isMeasureHorizontal) {
        return crosstabItem.getMeasure(0).getAggregationCell(null,null,colDimension,colLevel);
      }
 else {
        for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
          CrosstabCellHandle aggCell=crosstabItem.getMeasure(i).getAggregationCell(null,null,colDimension,colLevel);
          if (aggCell != null) {
            return aggCell;
          }
        }
      }
    }
 else     if (cell.getContainer() instanceof CrosstabReportItemHandle) {
      LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
      if (colLevelHandle != null) {
        return colLevelHandle.getCell();
      }
      if (isMeasureHorizontal) {
        for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
          MeasureViewHandle mv=crosstabItem.getMeasure(i);
          if (mv.getHeader() != null) {
            return mv.getHeader();
          }
        }
      }
      return cell;
    }
  }
  return null;
}