Program: 69780
Project: 69780
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);
      if (colLevelHandle == null) {
        return mv.getCell();
      }
      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) {
        MeasureViewHandle mv=(MeasureViewHandle)cell.getContainer();
        int headerPos=cell.getModelHandle().getIndex();
        if (headerPos > 0) {
          List<LevelViewHandle> levels=CrosstabModelUtil.getAllAggregationLevels(crosstabItem,COLUMN_AXIS_TYPE);
          Collections.reverse(levels);
          String rowDimension=null;
          String rowLevel=null;
          LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
          if (rowLevelHandle != null) {
            rowDimension=((DimensionViewHandle)rowLevelHandle.getContainer()).getCubeDimensionName();
            rowLevel=rowLevelHandle.getCubeLevelName();
          }
          int realIndex=1;
          for (int i=1; i < levels.size(); i++) {
            LevelViewHandle lv=levels.get(i);
            if (CrosstabModelUtil.isAggregationOn(mv,lv.getCubeLevelName(),COLUMN_AXIS_TYPE)) {
              if (headerPos == realIndex) {
                String colDimension=((DimensionViewHandle)lv.getContainer()).getCubeDimensionName();
                String colLevel=lv.getCubeLevelName();
                return mv.getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
              }
              realIndex++;
            }
          }
          return mv.getAggregationCell(rowDimension,rowLevel,null,null);
        }
        return mv.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;
}

Fixed version (ground truth):
/** 
 * Locates the cell which controls the column width 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);
      if (colLevelHandle == null) {
        return mv.getCell();
      }
      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) {
        MeasureViewHandle mv=(MeasureViewHandle)cell.getContainer();
        int headerPos=cell.getModelHandle().getIndex();
        if (headerPos > 0) {
          List<LevelViewHandle> levels=CrosstabModelUtil.getAllAggregationLevels(crosstabItem,COLUMN_AXIS_TYPE);
          Collections.reverse(levels);
          String rowDimension=null;
          String rowLevel=null;
          LevelViewHandle rowLevelHandle=getInnerMostLevel(crosstabItem,ROW_AXIS_TYPE);
          if (rowLevelHandle != null) {
            rowDimension=((DimensionViewHandle)rowLevelHandle.getContainer()).getCubeDimensionName();
            rowLevel=rowLevelHandle.getCubeLevelName();
          }
          int realIndex=1;
          for (int i=1; i < levels.size(); i++) {
            LevelViewHandle lv=levels.get(i);
            if (CrosstabModelUtil.isAggregationOn(mv,lv.getCubeLevelName(),COLUMN_AXIS_TYPE)) {
              if (headerPos == realIndex) {
                String colDimension=((DimensionViewHandle)lv.getContainer()).getCubeDimensionName();
                String colLevel=lv.getCubeLevelName();
                return mv.getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
              }
              realIndex++;
            }
          }
          return mv.getAggregationCell(rowDimension,rowLevel,null,null);
        }
        return mv.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;
}