Program: 81522
Project: 81522
Buggy source:
public void updateWorkbookFormulas(BlockTransformation transformation){
  Set sheetNames=sheetFormulasMap.keySet();
  Formula formula, newFormula;
  Set cellRefs, newCellRefs;
  CellRef cellRef, newCellRef;
  List resultCells;
  String newCell;
  Point point, newPoint;
  Set cellRefsToRemove=new HashSet();
  Set formulasToRemove=new HashSet();
  for (Iterator iterator=sheetNames.iterator(); iterator.hasNext(); ) {
    String sheetName=(String)iterator.next();
    List formulas=(List)sheetFormulasMap.get(sheetName);
    formulasToRemove.clear();
    for (int i=0, size=formulas.size(); i < size; i++) {
      formula=(Formula)formulas.get(i);
      List formulaPoints=null;
      Point formulaPoint=null;
      boolean transformFormula=false;
      if (formula.getSheet().getSheetName().equals(transformation.getBlock().getSheet().getSheetName())) {
        transformFormula=true;
        formulaPoint=new Point(formula.getRowNum().intValue(),formula.getCellNum().shortValue());
        formulaPoints=transformation.transformCell(formulaPoint);
      }
      if (!transformFormula || (formulaPoints != null && !formulaPoints.isEmpty())) {
        cellRefs=formula.getCellRefs();
        cellRefsToRemove.clear();
        for (Iterator iter=cellRefs.iterator(); iter.hasNext(); ) {
          cellRef=(CellRef)iter.next();
          if (!(transformation instanceof DuplicateTransformation && transformation.getBlock().contains(cellRef) && transformation.getBlock().contains(formula.getRowNum().intValue(),formula.getCellNum().intValue()))) {
            resultCells=transformation.transformCell(sheetName,cellRef);
            if (resultCells != null) {
              if (resultCells.size() == 1) {
                newCell=(String)resultCells.get(0);
                cellRef.update(newCell);
              }
 else               if (resultCells.size() > 1) {
                cellRef.update(resultCells);
              }
            }
 else {
              cellRefsToRemove.add(cellRef);
            }
          }
        }
        if (!cellRefsToRemove.isEmpty()) {
          formula.removeCellRefs(cellRefsToRemove);
        }
        formula.updateReplacedRefCellsCollection();
        if (formulaPoints != null && !formulaPoints.isEmpty()) {
          if (formulaPoints.size() == 1) {
            newPoint=(Point)formulaPoints.get(0);
            formula.setRowNum(new Integer(newPoint.getRow()));
            formula.setCellNum(new Integer(newPoint.getCol()));
          }
 else {
            List sheetFormulas=(List)sheetFormulasMap.get(formula.getSheet().getSheetName());
            for (int j=1, num=formulaPoints.size(); j < num; j++) {
              point=(Point)formulaPoints.get(j);
              newFormula=new Formula(formula);
              newFormula.setRowNum(new Integer(point.getRow()));
              newFormula.setCellNum(new Integer(point.getCol()));
              newCellRefs=newFormula.getCellRefs();
              for (Iterator iterator1=newCellRefs.iterator(); iterator1.hasNext(); ) {
                newCellRef=(CellRef)iterator1.next();
                if (transformation.getBlock().contains(newCellRef) && transformation.getBlock().contains(formulaPoint)) {
                  newCellRef.update(transformation.getDuplicatedCellRef(sheetName,newCellRef.toString(),j));
                }
              }
              sheetFormulas.add(newFormula);
            }
          }
        }
      }
 else {
        if (formulaPoints == null) {
          formulasToRemove.add(formula);
        }
      }
    }
    formulas.removeAll(formulasToRemove);
  }
}

Fixed version (ground truth):
public void updateWorkbookFormulas(BlockTransformation transformation){
  Set sheetNames=sheetFormulasMap.keySet();
  Formula formula, newFormula;
  Set cellRefs, newCellRefs;
  CellRef cellRef, newCellRef;
  List resultCells;
  String newCell;
  Point point, newPoint;
  Set cellRefsToRemove=new HashSet();
  Set formulasToRemove=new HashSet();
  for (Iterator iterator=sheetNames.iterator(); iterator.hasNext(); ) {
    String sheetName=(String)iterator.next();
    List formulas=(List)sheetFormulasMap.get(sheetName);
    formulasToRemove.clear();
    for (int i=0, size=formulas.size(); i < size; i++) {
      formula=(Formula)formulas.get(i);
      List formulaPoints=null;
      Point formulaPoint=null;
      boolean transformFormula=false;
      if (formula.getSheet().getSheetName().equals(transformation.getBlock().getSheet().getSheetName())) {
        transformFormula=true;
        formulaPoint=new Point(formula.getRowNum().intValue(),formula.getCellNum().shortValue());
        formulaPoints=transformation.transformCell(formulaPoint);
      }
      if (!transformFormula || (formulaPoints != null && !formulaPoints.isEmpty())) {
        cellRefs=formula.getCellRefs();
        cellRefsToRemove.clear();
        for (Iterator iter=cellRefs.iterator(); iter.hasNext(); ) {
          cellRef=(CellRef)iter.next();
          if (!(transformation instanceof DuplicateTransformation && transformation.getBlock().contains(cellRef) && transformation.getBlock().contains(formula))) {
            resultCells=transformation.transformCell(sheetName,cellRef);
            if (resultCells != null) {
              if (resultCells.size() == 1) {
                newCell=(String)resultCells.get(0);
                cellRef.update(newCell);
              }
 else               if (resultCells.size() > 1) {
                cellRef.update(resultCells);
              }
            }
 else {
              cellRefsToRemove.add(cellRef);
            }
          }
        }
        if (!cellRefsToRemove.isEmpty()) {
          formula.removeCellRefs(cellRefsToRemove);
        }
        formula.updateReplacedRefCellsCollection();
        if (formulaPoints != null && !formulaPoints.isEmpty()) {
          if (formulaPoints.size() == 1) {
            newPoint=(Point)formulaPoints.get(0);
            formula.setRowNum(new Integer(newPoint.getRow()));
            formula.setCellNum(new Integer(newPoint.getCol()));
          }
 else {
            List sheetFormulas=(List)sheetFormulasMap.get(formula.getSheet().getSheetName());
            for (int j=1, num=formulaPoints.size(); j < num; j++) {
              point=(Point)formulaPoints.get(j);
              newFormula=new Formula(formula);
              newFormula.setRowNum(new Integer(point.getRow()));
              newFormula.setCellNum(new Integer(point.getCol()));
              newCellRefs=newFormula.getCellRefs();
              for (Iterator iterator1=newCellRefs.iterator(); iterator1.hasNext(); ) {
                newCellRef=(CellRef)iterator1.next();
                if (transformation.getBlock().contains(newCellRef) && transformation.getBlock().contains(formulaPoint)) {
                  newCellRef.update(transformation.getDuplicatedCellRef(sheetName,newCellRef.toString(),j));
                }
              }
              sheetFormulas.add(newFormula);
            }
          }
        }
      }
 else {
        if (formulaPoints == null) {
          formulasToRemove.add(formula);
        }
      }
    }
    formulas.removeAll(formulasToRemove);
  }
}