Program: 65779
Project: 65779
Buggy source:
public static void updateHeaderCell(CrosstabReportItemHandle crosstab,int pos,int axisType,boolean isMoveDimension,int adjustCount){
  HeaderData data=calcHeaderData(crosstab);
  List<LevelViewHandle> rowLevelList=getLevelList(crosstab,ICrosstabConstants.ROW_AXIS_TYPE);
  if (isMoveDimension) {
    if (ICrosstabConstants.COLUMN_AXIS_TYPE == axisType) {
      data.rowNumber=data.rowNumber - adjustCount;
    }
 else {
      data.columnNumber=data.columnNumber - adjustCount;
    }
  }
  int total=data.rowNumber * data.columnNumber;
  PropertyHandle headerHandle=crosstab.getModelHandle().getPropertyHandle(ICrosstabReportItemConstants.HEADER_PROP);
  if (pos == -1) {
    if (ICrosstabConstants.MEASURE_DIRECTION_VERTICAL.equals(crosstab.getMeasureDirection())) {
      pos=total - crosstab.getHeaderCount() > 0 ? data.columnNumber - 1 : data.columnNumber;
      axisType=ICrosstabConstants.ROW_AXIS_TYPE;
    }
 else {
      pos=total - crosstab.getHeaderCount() > 0 ? data.rowNumber - 1 : data.rowNumber;
      axisType=ICrosstabConstants.COLUMN_AXIS_TYPE;
    }
  }
 else   if (pos == -2 && !crosstab.isHideMeasureHeader() && crosstab.getMeasureCount() > 0) {
    if (ICrosstabConstants.MEASURE_DIRECTION_VERTICAL.equals(crosstab.getMeasureDirection())) {
      if (total - crosstab.getHeaderCount() != data.rowNumber) {
        for (int i=0; i < data.columnNumber - 1; i++) {
          try {
            headerHandle.removeItem((data.rowNumber - 1) * (data.columnNumber - 1));
          }
 catch (          PropertyValueException e) {
          }
        }
      }
    }
 else {
      if (total - crosstab.getHeaderCount() != data.columnNumber) {
        for (int i=data.rowNumber - 2; i >= 0; i--) {
          try {
            int delPos=data.columnNumber - 1;
            if (i == data.rowNumber - 2) {
              delPos=data.columnNumber;
            }
            headerHandle.removeItem(i * (data.columnNumber + 1) + delPos);
          }
 catch (          PropertyValueException e) {
          }
        }
      }
    }
    if (ICrosstabConstants.MEASURE_DIRECTION_VERTICAL.equals(crosstab.getMeasureDirection())) {
      pos=data.columnNumber - 1;
      axisType=ICrosstabConstants.ROW_AXIS_TYPE;
    }
 else {
      pos=data.rowNumber - 1;
      axisType=ICrosstabConstants.COLUMN_AXIS_TYPE;
    }
  }
  boolean isAdd=total - crosstab.getHeaderCount() > 0;
  if (!isMoveDimension && !needUpdateHeaderCell(crosstab,isAdd,axisType)) {
    return;
  }
  if (total == crosstab.getHeaderCount()) {
    return;
  }
  if (ICrosstabConstants.COLUMN_AXIS_TYPE == axisType) {
    for (int i=0; i < data.columnNumber; i++) {
      try {
        if (isAdd) {
          int insertRow=pos;
          if (insertRow == data.rowNumber - 1 && rowLevelList.size() != 0) {
            insertRow=insertRow - 1;
          }
          ExtendedItemHandle cellHandle=CrosstabExtendedItemFactory.createCrosstabCell(crosstab.getModuleHandle());
          headerHandle.add(cellHandle,insertRow * data.columnNumber + i);
        }
 else {
          headerHandle.removeItem((pos == data.rowNumber ? pos - 1 : pos) * data.columnNumber);
        }
      }
 catch (      SemanticException e) {
      }
    }
  }
 else {
    for (int i=data.rowNumber - 1; i >= 0; i--) {
      try {
        if (isAdd) {
          int insertColumn=pos;
          if (pos == data.columnNumber - 1 && i != data.rowNumber - 1) {
            insertColumn=pos - 1;
          }
          ExtendedItemHandle cellHandle=CrosstabExtendedItemFactory.createCrosstabCell(crosstab.getModuleHandle());
          headerHandle.add(cellHandle,i * (data.columnNumber - 1) + insertColumn);
        }
 else {
          int newPos=pos;
          if (pos == data.columnNumber && i != data.rowNumber - 1) {
            newPos=pos - 1;
          }
          headerHandle.removeItem(i * (data.columnNumber + 1) + newPos);
        }
      }
 catch (      SemanticException e) {
      }
    }
  }
}

Fixed version (ground truth):
public static void updateHeaderCell(CrosstabReportItemHandle crosstab,int pos,int axisType,boolean isMoveDimension,int adjustCount,boolean removeLevel){
  HeaderData data=calcHeaderData(crosstab);
  List<LevelViewHandle> rowLevelList=getLevelList(crosstab,ICrosstabConstants.ROW_AXIS_TYPE);
  if (isMoveDimension) {
    if (ICrosstabConstants.COLUMN_AXIS_TYPE == axisType) {
      data.rowNumber=data.rowNumber - adjustCount;
    }
 else {
      data.columnNumber=data.columnNumber - adjustCount;
    }
  }
  int total=data.rowNumber * data.columnNumber;
  PropertyHandle headerHandle=crosstab.getModelHandle().getPropertyHandle(ICrosstabReportItemConstants.HEADER_PROP);
  if (pos == -1) {
    if (ICrosstabConstants.MEASURE_DIRECTION_VERTICAL.equals(crosstab.getMeasureDirection())) {
      pos=total - crosstab.getHeaderCount() > 0 ? data.columnNumber - 1 : data.columnNumber;
      axisType=ICrosstabConstants.ROW_AXIS_TYPE;
    }
 else {
      pos=total - crosstab.getHeaderCount() > 0 ? data.rowNumber - 1 : data.rowNumber;
      axisType=ICrosstabConstants.COLUMN_AXIS_TYPE;
    }
  }
 else   if (pos == -2 && !crosstab.isHideMeasureHeader() && crosstab.getMeasureCount() > 0) {
    if (ICrosstabConstants.MEASURE_DIRECTION_VERTICAL.equals(crosstab.getMeasureDirection())) {
      if (total - crosstab.getHeaderCount() != data.rowNumber) {
        for (int i=0; i < data.columnNumber - 1; i++) {
          try {
            headerHandle.removeItem((data.rowNumber - 1) * (data.columnNumber - 1));
          }
 catch (          PropertyValueException e) {
          }
        }
      }
    }
 else {
      if (total - crosstab.getHeaderCount() != data.columnNumber) {
        for (int i=data.rowNumber - 2; i >= 0; i--) {
          try {
            int delPos=data.columnNumber - 1;
            if (i == data.rowNumber - 2) {
              delPos=data.columnNumber;
            }
            headerHandle.removeItem(i * (data.columnNumber + 1) + delPos);
          }
 catch (          PropertyValueException e) {
          }
        }
      }
    }
    if (ICrosstabConstants.MEASURE_DIRECTION_VERTICAL.equals(crosstab.getMeasureDirection())) {
      pos=data.columnNumber - 1;
      axisType=ICrosstabConstants.ROW_AXIS_TYPE;
    }
 else {
      pos=data.rowNumber - 1;
      axisType=ICrosstabConstants.COLUMN_AXIS_TYPE;
    }
  }
  boolean isAdd=total - crosstab.getHeaderCount() > 0;
  if (!isMoveDimension && !needUpdateHeaderCell(crosstab,removeLevel ? false : isAdd,axisType)) {
    return;
  }
  if (total == crosstab.getHeaderCount()) {
    return;
  }
  if (ICrosstabConstants.COLUMN_AXIS_TYPE == axisType) {
    for (int i=0; i < data.columnNumber; i++) {
      try {
        if (isAdd) {
          int insertRow=pos;
          if (insertRow == data.rowNumber - 1 && rowLevelList.size() != 0) {
            insertRow=insertRow - 1;
          }
          ExtendedItemHandle cellHandle=CrosstabExtendedItemFactory.createCrosstabCell(crosstab.getModuleHandle());
          headerHandle.add(cellHandle,insertRow * data.columnNumber + i);
        }
 else {
          headerHandle.removeItem((pos == data.rowNumber ? pos - 1 : pos) * data.columnNumber);
        }
      }
 catch (      SemanticException e) {
      }
    }
  }
 else {
    for (int i=data.rowNumber - 1; i >= 0; i--) {
      try {
        if (isAdd) {
          int insertColumn=pos;
          if (pos == data.columnNumber - 1 && i != data.rowNumber - 1) {
            insertColumn=pos - 1;
          }
          ExtendedItemHandle cellHandle=CrosstabExtendedItemFactory.createCrosstabCell(crosstab.getModuleHandle());
          headerHandle.add(cellHandle,i * (data.columnNumber - 1) + insertColumn);
        }
 else {
          int newPos=pos;
          if (pos == data.columnNumber && i != data.rowNumber - 1) {
            newPos=pos - 1;
          }
          headerHandle.removeItem(i * (data.columnNumber + 1) + newPos);
        }
      }
 catch (      SemanticException e) {
      }
    }
  }
}