Program: 74203
Project: 74203
Buggy source:
/** 
 * Locates the cell which controls the column with for given cell
 * @param crosstabItem
 * @param cell
 * @return
 */
public static CrosstabCellHandle locateColumnWidthCell(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 colDimension=aggCell.getDimensionName(COLUMN_AXIS_TYPE);
      String colLevel=aggCell.getLevelName(COLUMN_AXIS_TYPE);
      LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
      DimensionViewHandle colDimHandle=(DimensionViewHandle)colLevelHandle.getContainer();
      if (colLevelHandle.getCubeLevelName().equals(colLevel) && colDimHandle.getCubeDimensionName().equals(colDimension)) {
        return mv.getCell();
      }
      String rowDimension=null;
      String rowLevel=null;
      LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
      if (rowLevelHandle != null) {
        rowDimension=((DimensionViewHandle)rowLevelHandle.getContainer()).getCubeDimensionName();
        rowLevel=rowLevelHandle.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,ROW_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,COLUMN_AXIS_TYPE).getCell();
      }
      if (ILevelViewConstants.AGGREGATION_HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
        String rowDimension=null;
        String rowLevel=null;
        String colDimension=((DimensionViewHandle)lv.getContainer()).getCubeDimensionName();
        String colLevel=lv.getCubeLevelName();
        LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
        if (rowLevelHandle != null) {
          rowDimension=((DimensionViewHandle)rowLevelHandle.getContainer()).getCubeDimensionName();
          rowLevel=rowLevelHandle.getCubeLevelName();
        }
        if (isMeasureHorizontal) {
          for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
            CrosstabCellHandle aggCell=crosstabItem.getMeasure(i).getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
            if (aggCell != null) {
              return aggCell;
            }
          }
        }
 else {
          return crosstabItem.getMeasure(0).getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
        }
      }
      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 rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
        if (rowLevelHandle != null) {
          return rowLevelHandle.getCell();
        }
        return cell;
      }
      if (crosstabItem.getMeasureCount() == 0) {
        return cell;
      }
      String rowDimension=null;
      String rowLevel=null;
      LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
      if (rowLevelHandle != null) {
        rowDimension=((DimensionViewHandle)rowLevelHandle.getContainer()).getCubeDimensionName();
        rowLevel=rowLevelHandle.getCubeLevelName();
      }
      if (isMeasureHorizontal) {
        for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
          CrosstabCellHandle aggCell=crosstabItem.getMeasure(i).getAggregationCell(rowDimension,rowLevel,null,null);
          if (aggCell != null) {
            return aggCell;
          }
        }
      }
 else {
        return crosstabItem.getMeasure(0).getAggregationCell(rowDimension,rowLevel,null,null);
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Locates the cell which controls the column with for given cell
 * @param crosstabItem
 * @param cell
 * @return
 */
public static CrosstabCellHandle locateColumnWidthCell(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 colDimension=aggCell.getDimensionName(COLUMN_AXIS_TYPE);
      String colLevel=aggCell.getLevelName(COLUMN_AXIS_TYPE);
      LevelViewHandle colLevelHandle=getInnerMostLevel(crosstabItem,COLUMN_AXIS_TYPE);
      DimensionViewHandle colDimHandle=(DimensionViewHandle)colLevelHandle.getContainer();
      if (colLevelHandle.getCubeLevelName().equals(colLevel) && colDimHandle.getCubeDimensionName().equals(colDimension)) {
        return mv.getCell();
      }
      String rowDimension=null;
      String rowLevel=null;
      LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
      if (rowLevelHandle != null) {
        rowDimension=((DimensionViewHandle)rowLevelHandle.getContainer()).getCubeDimensionName();
        rowLevel=rowLevelHandle.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,ROW_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,COLUMN_AXIS_TYPE).getCell();
      }
      if (ILevelViewConstants.AGGREGATION_HEADER_PROP.equals(cell.getModelHandle().getContainerPropertyHandle().getPropertyDefn().getName())) {
        String rowDimension=null;
        String rowLevel=null;
        String colDimension=((DimensionViewHandle)lv.getContainer()).getCubeDimensionName();
        String colLevel=lv.getCubeLevelName();
        LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
        if (rowLevelHandle != null) {
          rowDimension=((DimensionViewHandle)rowLevelHandle.getContainer()).getCubeDimensionName();
          rowLevel=rowLevelHandle.getCubeLevelName();
        }
        if (isMeasureHorizontal) {
          for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
            CrosstabCellHandle aggCell=crosstabItem.getMeasure(i).getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
            if (aggCell != null) {
              return aggCell;
            }
          }
        }
 else {
          return crosstabItem.getMeasure(0).getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
        }
      }
      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 rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
        if (rowLevelHandle != null) {
          return rowLevelHandle.getCell();
        }
        return cell;
      }
      if (crosstabItem.getMeasureCount() == 0) {
        return cell;
      }
      String rowDimension=null;
      String rowLevel=null;
      LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
      if (rowLevelHandle != null) {
        rowDimension=((DimensionViewHandle)rowLevelHandle.getContainer()).getCubeDimensionName();
        rowLevel=rowLevelHandle.getCubeLevelName();
      }
      if (isMeasureHorizontal) {
        for (int i=0; i < crosstabItem.getMeasureCount(); i++) {
          CrosstabCellHandle aggCell=crosstabItem.getMeasure(i).getAggregationCell(rowDimension,rowLevel,null,null);
          if (aggCell != null) {
            return aggCell;
          }
        }
      }
 else {
        return crosstabItem.getMeasure(0).getAggregationCell(rowDimension,rowLevel,null,null);
      }
    }
 else     if (cell.getContainer() instanceof CrosstabReportItemHandle) {
      LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
      if (rowLevelHandle != null) {
        return rowLevelHandle.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;
}