nus-yam/ex-repair huggingface dataset:
Program: 81478
Project: 81478
Buggy source:
public void testFormulaWhenTopRowsAreNull() throws InvalidFormatException, IOException {
  Map beans=new HashMap();
  beans.put("String_Node_Str",itDepartment);
  InputStream is=new BufferedInputStream(getClass().getResourceAsStream(formulaXLS));
  XLSTransformer transformer=new XLSTransformer();
  Workbook resultWorkbook=transformer.transformXLS(is,beans);
  is.close();
  saveWorkbook(resultWorkbook,formulaDestXLS);
}

Fixed version (ground truth):
public void testFormulaWhenTopRowsAreNull() throws InvalidFormatException, IOException {
  Map beans=new HashMap();
  beans.put("String_Node_Str",itDepartment);
  InputStream is=new BufferedInputStream(getClass().getResourceAsStream(formulaXLS));
  XLSTransformer transformer=new XLSTransformer();
  Workbook resultWorkbook=transformer.transformXLS(is,beans);
  Sheet resultSheet=resultWorkbook.getSheetAt(0);
  CellsChecker checker=new CellsChecker();
  checker.checkCell(resultSheet,8,1,1500);
  checker.checkCell(resultSheet,9,1,2300);
  checker.checkFormulaCell(resultSheet,13,1,"String_Node_Str");
  is.close();
  saveWorkbook(resultWorkbook,formulaDestXLS);
}
Program: 81479
Project: 81479
Buggy source:
public SheetTransformationControllerImpl(Sheet sheet){
  this.sheet=sheet;
  helper=new TagBodyHelper();
  formulaController=sheet.getWorkbook().getFormulaController();
}

Fixed version (ground truth):
public SheetTransformationControllerImpl(Sheet sheet){
  this.sheet=sheet;
  formulaController=sheet.getWorkbook().getFormulaController();
}
Program: 81480
Project: 81480
Buggy source:
String buildCommaSeparatedListOfCells(String refSheetName,List cells){
  String listOfCells="String_Node_Str";
  for (int i=0; i < cells.size() - 1; i++) {
    String cell=(String)cells.get(i);
    listOfCells+=getRefCellName(refSheetName,cell) + "String_Node_Str";
  }
  listOfCells+=getRefCellName(refSheetName,(String)cells.get(cells.size() - 1));
  return listOfCells;
}

Fixed version (ground truth):
String buildCommaSeparatedListOfCells(String refSheetName,List cells){
  StringBuilder buf=new StringBuilder();
  for (int i=0; i < cells.size() - 1; i++) {
    String cell=(String)cells.get(i);
    buf.append(getRefCellName(refSheetName,cell));
    buf.append("String_Node_Str");
  }
  buf.append(getRefCellName(refSheetName,(String)cells.get(cells.size() - 1)));
  return buf.toString();
}
Program: 81481
Project: 81481
Buggy source:
/** 
 * Method to replace coded list ranges (like @department.staff.payment@) with excel range string like B10:B20
 * @param formula - {@link Formula} object to replace list ranges in
 * @return Formula string that should be set into Excel cell using POI
 */
String replaceListRanges(Formula formula){
  String codedFormula=formula.getFormula();
  Sheet sheet=formula.getSheet();
  String appliedFormula="String_Node_Str";
  String delimiter=formulaListRangeToken;
  int index=codedFormula.indexOf(delimiter);
  boolean isExpression=false;
  while (index >= 0) {
    String token=codedFormula.substring(0,index);
    if (isExpression) {
      if (sheet.getListRanges().containsKey(token)) {
        appliedFormula+=((ListRange)sheet.getListRanges().get(token)).toExcelCellRange();
      }
 else       if (sheet.getNamedCells().containsKey(token)) {
        appliedFormula+=((Cell)sheet.getNamedCells().get(token)).toCellName();
      }
 else {
        log.warn("String_Node_Str" + token);
        return null;
      }
    }
 else {
      appliedFormula+=token;
    }
    codedFormula=codedFormula.substring(index + 1);
    index=codedFormula.indexOf(delimiter);
    isExpression=!isExpression;
  }
  appliedFormula+=codedFormula;
  return appliedFormula;
}

Fixed version (ground truth):
/** 
 * Method to replace coded list ranges (like @department.staff.payment@) with excel range string like B10:B20
 * @param formula - {@link Formula} object to replace list ranges in
 * @return Formula string that should be set into Excel cell using POI
 */
String replaceListRanges(Formula formula){
  String codedFormula=formula.getFormula();
  Sheet sheet=formula.getSheet();
  StringBuilder appliedFormulaBuilder=new StringBuilder();
  String delimiter=formulaListRangeToken;
  int index=codedFormula.indexOf(delimiter);
  boolean isExpression=false;
  while (index >= 0) {
    String token=codedFormula.substring(0,index);
    if (isExpression) {
      if (sheet.getListRanges().containsKey(token)) {
        appliedFormulaBuilder.append(((ListRange)sheet.getListRanges().get(token)).toExcelCellRange());
      }
 else       if (sheet.getNamedCells().containsKey(token)) {
        appliedFormulaBuilder.append(((Cell)sheet.getNamedCells().get(token)).toCellName());
      }
 else {
        log.warn("String_Node_Str" + token);
        return null;
      }
    }
 else {
      appliedFormulaBuilder.append(token);
    }
    codedFormula=codedFormula.substring(index + 1);
    index=codedFormula.indexOf(delimiter);
    isExpression=!isExpression;
  }
  appliedFormulaBuilder.append(codedFormula);
  return appliedFormulaBuilder.toString();
}
Program: 81482
Project: 81482
Buggy source:
String buildCommaSeparatedListOfCells(String refSheetName,List cells){
  String listOfCells="String_Node_Str";
  for (int i=0; i < cells.size() - 1; i++) {
    String cell=(String)cells.get(i);
    String refCellName=getRefCellName(refSheetName,cell);
    listOfCells+=refCellName + "String_Node_Str";
    rangeFormulaParts.add(new CellRef(refCellName,parentFormula));
    rangeFormulaParts.add("String_Node_Str");
  }
  String refCellName=getRefCellName(refSheetName,(String)cells.get(cells.size() - 1));
  listOfCells+=refCellName;
  rangeFormulaParts.add(new CellRef(refCellName,parentFormula));
  return listOfCells;
}

Fixed version (ground truth):
String buildCommaSeparatedListOfCells(String refSheetName,List cells){
  StringBuilder listOfCellsBuilder=new StringBuilder();
  for (int i=0; i < cells.size() - 1; i++) {
    String cell=(String)cells.get(i);
    String refCellName=getRefCellName(refSheetName,cell);
    listOfCellsBuilder.append(refCellName);
    listOfCellsBuilder.append("String_Node_Str");
    rangeFormulaParts.add(new CellRef(refCellName,parentFormula));
    rangeFormulaParts.add("String_Node_Str");
  }
  String refCellName=getRefCellName(refSheetName,(String)cells.get(cells.size() - 1));
  listOfCellsBuilder.append(refCellName);
  rangeFormulaParts.add(new CellRef(refCellName,parentFormula));
  return listOfCellsBuilder.toString();
}
Program: 81483
Project: 81483
Buggy source:
/** 
 * @return Formula string that should be set into Excel cell using POI
 */
public String getAppliedFormula(Map listRanges,Map namedCells){
  String codedFormula=formula;
  String appliedFormula="String_Node_Str";
  String delimiter=formulaListRangeToken;
  int index=codedFormula.indexOf(delimiter);
  boolean isExpression=false;
  while (index >= 0) {
    String token=codedFormula.substring(0,index);
    if (isExpression) {
      if (listRanges.containsKey(token)) {
        appliedFormula+=((ListRange)listRanges.get(token)).toExcelCellRange();
      }
 else       if (namedCells.containsKey(token)) {
        appliedFormula+=((Cell)namedCells.get(token)).toCellName();
      }
 else {
        log.warn("String_Node_Str" + token);
        return null;
      }
    }
 else {
      appliedFormula+=token;
    }
    codedFormula=codedFormula.substring(index + 1);
    index=codedFormula.indexOf(delimiter);
    isExpression=!isExpression;
  }
  appliedFormula+=codedFormula;
  return appliedFormula;
}

Fixed version (ground truth):
/** 
 * @return Formula string that should be set into Excel cell using POI
 */
public String getAppliedFormula(Map listRanges,Map namedCells){
  String codedFormula=formula;
  StringBuilder appliedFormulaBuilder=new StringBuilder();
  String delimiter=formulaListRangeToken;
  int index=codedFormula.indexOf(delimiter);
  boolean isExpression=false;
  while (index >= 0) {
    String token=codedFormula.substring(0,index);
    if (isExpression) {
      if (listRanges.containsKey(token)) {
        appliedFormulaBuilder.append(((ListRange)listRanges.get(token)).toExcelCellRange());
      }
 else       if (namedCells.containsKey(token)) {
        appliedFormulaBuilder.append(((Cell)namedCells.get(token)).toCellName());
      }
 else {
        log.warn("String_Node_Str" + token);
        return null;
      }
    }
 else {
      appliedFormulaBuilder.append(token);
    }
    codedFormula=codedFormula.substring(index + 1);
    index=codedFormula.indexOf(delimiter);
    isExpression=!isExpression;
  }
  appliedFormulaBuilder.append(codedFormula);
  return appliedFormulaBuilder.toString();
}
Program: 81484
Project: 81484
Buggy source:
public String getActualFormula(){
  FormulaPart formulaPart;
  String actualFormula="String_Node_Str";
  for (Iterator iterator=formulaParts.iterator(); iterator.hasNext(); ) {
    formulaPart=(FormulaPart)iterator.next();
    actualFormula+=formulaPart.getActualFormula();
  }
  return actualFormula;
}

Fixed version (ground truth):
public String getActualFormula(){
  FormulaPart formulaPart;
  StringBuilder actualFormulaBuilder=new StringBuilder();
  for (Iterator iterator=formulaParts.iterator(); iterator.hasNext(); ) {
    formulaPart=(FormulaPart)iterator.next();
    actualFormulaBuilder.append(formulaPart.getActualFormula());
  }
  return actualFormulaBuilder.toString();
}
Program: 81485
Project: 81485
Buggy source:
public FormulaControllerImpl(Workbook workbook){
  this.workbook=workbook;
  sheetFormulasMap=workbook.createFormulaSheetMap();
}

Fixed version (ground truth):
public FormulaControllerImpl(Workbook workbook){
  sheetFormulasMap=workbook.createFormulaSheetMap();
}
Program: 81487
Project: 81487
Buggy source:
private static List findFormulasInRow(Sheet sheet,org.apache.poi.ss.usermodel.Row hssfRow){
  List formulas=new ArrayList();
  if (hssfRow != null) {
    Row row=new Row(sheet,hssfRow);
    CellParser cellParser;
    Formula formula;
    Cell hssfCell;
    for (int i=hssfRow.getFirstCellNum(); i <= hssfRow.getLastCellNum(); i++) {
      hssfCell=hssfRow.getCell(i);
      if (hssfCell != null) {
        cellParser=new CellParser(hssfCell,row,sheet.getConfiguration());
        if (cellParser.parseCellFormula() != null && !cellParser.getCell().getFormula().isInline()) {
          formula=cellParser.getCell().getFormula();
          formula.setSheet(sheet);
          formulas.add(formula);
        }
      }
    }
  }
  return formulas;
}

Fixed version (ground truth):
private static List findFormulasInRow(Sheet sheet,org.apache.poi.ss.usermodel.Row hssfRow){
  List formulas=new ArrayList();
  if (hssfRow != null) {
    Row row=new Row(sheet,hssfRow);
    CellParser cellParser;
    Formula formula;
    Cell hssfCell;
    for (int i=hssfRow.getFirstCellNum(); i <= hssfRow.getLastCellNum() && i > -1; i++) {
      hssfCell=hssfRow.getCell(i);
      if (hssfCell != null) {
        cellParser=new CellParser(hssfCell,row,sheet.getConfiguration());
        if (cellParser.parseCellFormula() != null && !cellParser.getCell().getFormula().isInline()) {
          formula=cellParser.getCell().getFormula();
          formula.setSheet(sheet);
          formulas.add(formula);
        }
      }
    }
  }
  return formulas;
}
Program: 81489
Project: 81489
Buggy source:
public static void removeLeftRightBorders(HSSFSheet sheet,Block block){
  HSSFRow row=sheet.getRow(block.getStartRowNum());
  if (row != null) {
    Util.shiftCellsLeft(sheet,block.getStartRowNum(),(int)(block.getStartCellNum() + 1),block.getEndRowNum(),row.getLastCellNum(),(int)1);
    HSSFCell cellToRemove=row.getCell(row.getLastCellNum());
    clearAndRemoveCell(row,cellToRemove);
    Util.shiftCellsLeft(sheet,block.getStartRowNum(),block.getEndCellNum(),block.getEndRowNum(),row.getLastCellNum(),(int)1);
    HSSFCell cell=cellToRemove;
    clearAndRemoveCell(row,cell);
    block.setEndCellNum((int)(block.getEndCellNum() - 2));
  }
}

Fixed version (ground truth):
public static void removeLeftRightBorders(HSSFSheet sheet,Block block){
  HSSFRow row=sheet.getRow(block.getStartRowNum());
  if (row != null) {
    Util.shiftCellsLeft(sheet,block.getStartRowNum(),(block.getStartCellNum() + 1),block.getEndRowNum(),row.getLastCellNum(),1,true);
    HSSFCell cellToRemove=row.getCell(row.getLastCellNum());
    clearAndRemoveCell(row,cellToRemove);
    Util.shiftCellsLeft(sheet,block.getStartRowNum(),block.getEndCellNum(),block.getEndRowNum(),row.getLastCellNum(),1,true);
    HSSFCell cell=cellToRemove;
    clearAndRemoveCell(row,cell);
    block.setEndCellNum((int)(block.getEndCellNum() - 2));
  }
}
Program: 81490
Project: 81490
Buggy source:
public static int duplicateRight(HSSFSheet sheet,Block block,int n){
  if (n > 0) {
    Util.shiftCellsRight(sheet,block.getStartRowNum(),block.getEndRowNum(),(int)(block.getEndCellNum() + 1),(int)(block.getNumberOfColumns() * n));
    for (int i=block.getStartRowNum(); i <= block.getEndRowNum(); i++) {
      HSSFRow row=sheet.getRow(i);
      if (row != null) {
        for (int k=0; k < n; k++) {
          for (int j=block.getStartCellNum(); j <= block.getEndCellNum(); j++) {
            int destCellNum=(int)(block.getEndCellNum() + k * block.getNumberOfColumns() + j - block.getStartCellNum() + 1);
            HSSFCell destCell=row.getCell(destCellNum);
            HSSFCell cell=row.getCell(j);
            if (destCell == null) {
              destCell=row.createCell(destCellNum);
            }
            Util.copyCell(cell,destCell,true);
            sheet.setColumnWidth(destCellNum,Util.getWidth(sheet,j));
          }
        }
      }
    }
    return block.getNumberOfColumns() * n;
  }
  return 0;
}

Fixed version (ground truth):
public static int duplicateRight(HSSFSheet sheet,Block block,int n){
  if (n > 0) {
    Set mergedRegions=new HashSet();
    Util.shiftCellsRight(sheet,block.getStartRowNum(),block.getEndRowNum(),(block.getEndCellNum() + 1),(block.getNumberOfColumns() * n),true);
    for (int rowNum=block.getStartRowNum(); rowNum <= block.getEndRowNum(); rowNum++) {
      HSSFRow row=sheet.getRow(rowNum);
      if (row != null) {
        for (int k=0; k < n; k++) {
          for (int cellNum=block.getStartCellNum(); cellNum <= block.getEndCellNum(); cellNum++) {
            int destCellNum=(block.getEndCellNum() + k * block.getNumberOfColumns() + cellNum - block.getStartCellNum() + 1);
            HSSFCell destCell=row.getCell(destCellNum);
            HSSFCell cell=row.getCell(cellNum);
            if (destCell == null) {
              destCell=row.createCell(destCellNum);
            }
            Util.copyCell(cell,destCell,true);
            Util.updateMergedRegionInRow(sheet,mergedRegions,rowNum,cellNum,destCellNum,false);
            sheet.setColumnWidth(destCellNum,Util.getWidth(sheet,cellNum));
          }
        }
      }
    }
    return block.getNumberOfColumns() * n;
  }
  return 0;
}
Program: 81491
Project: 81491
Buggy source:
public static void removeRowCells(HSSFSheet sheet,HSSFRow row,int startCellNum,int endCellNum){
  clearRowCells(row,startCellNum,endCellNum);
  Util.shiftCellsLeft(sheet,row.getRowNum(),(int)(endCellNum + 1),row.getRowNum(),row.getLastCellNum(),(int)(endCellNum - startCellNum + 1));
  clearRowCells(row,(int)(row.getLastCellNum() - (endCellNum - startCellNum)),row.getLastCellNum());
}

Fixed version (ground truth):
public static void removeRowCells(HSSFSheet sheet,HSSFRow row,int startCellNum,int endCellNum){
  clearRowCells(row,startCellNum,endCellNum);
  Util.shiftCellsLeft(sheet,row.getRowNum(),(int)(endCellNum + 1),row.getRowNum(),row.getLastCellNum(),(int)(endCellNum - startCellNum + 1),true);
  clearRowCells(row,(int)(row.getLastCellNum() - (endCellNum - startCellNum)),row.getLastCellNum());
}
Program: 81492
Project: 81492
Buggy source:
public static void shiftCellsLeft(HSSFSheet sheet,int startRow,int startCol,int endRow,int endCol,int shiftNumber){
  for (int i=startRow; i <= endRow; i++) {
    boolean doSetWidth=true;
    HSSFRow row=sheet.getRow(i);
    if (row != null) {
      for (int j=startCol; j <= endCol; j++) {
        HSSFCell cell=row.getCell(j);
        if (cell == null) {
          cell=row.createCell(j);
          doSetWidth=false;
        }
        HSSFCell destCell=row.getCell((int)(j - shiftNumber));
        if (destCell == null) {
          destCell=row.createCell((int)(j - shiftNumber));
        }
        copyCell(cell,destCell,true);
        if (doSetWidth) {
          sheet.setColumnWidth(destCell.getColumnIndex(),getWidth(sheet,cell.getColumnIndex()));
        }
      }
    }
  }
}

Fixed version (ground truth):
public static void shiftCellsLeft(HSSFSheet sheet,int startRow,int startCol,int endRow,int endCol,int shiftNumber,boolean removeSourceMergedRegion){
  Set mergedRegions=new HashSet();
  for (int rowNum=startRow; rowNum <= endRow; rowNum++) {
    boolean doSetWidth=true;
    HSSFRow row=sheet.getRow(rowNum);
    if (row != null) {
      for (int colNum=startCol; colNum <= endCol; colNum++) {
        HSSFCell cell=row.getCell(colNum);
        if (cell == null) {
          cell=row.createCell(colNum);
          doSetWidth=false;
        }
        int destColNum=colNum - shiftNumber;
        HSSFCell destCell=row.getCell(destColNum);
        if (destCell == null) {
          destCell=row.createCell(destColNum);
        }
        copyCell(cell,destCell,true);
        Util.updateMergedRegionInRow(sheet,mergedRegions,rowNum,colNum,destColNum,removeSourceMergedRegion);
        if (doSetWidth) {
          sheet.setColumnWidth(destCell.getColumnIndex(),getWidth(sheet,cell.getColumnIndex()));
        }
      }
    }
  }
}
Program: 81493
Project: 81493
Buggy source:
public static void shiftCellsRight(HSSFSheet sheet,int startRow,int endRow,int startCol,int shiftNumber){
  for (int i=startRow; i <= endRow; i++) {
    HSSFRow row=sheet.getRow(i);
    if (row != null) {
      int lastCellNum=row.getLastCellNum();
      for (int j=lastCellNum; j >= startCol; j--) {
        HSSFCell destCell=row.getCell((int)(j + shiftNumber));
        if (destCell == null) {
          destCell=row.createCell((int)(j + shiftNumber));
        }
        HSSFCell cell=row.getCell(j);
        if (cell == null) {
          cell=row.createCell(j);
        }
        copyCell(cell,destCell,true);
      }
    }
  }
}

Fixed version (ground truth):
public static void shiftCellsRight(HSSFSheet sheet,int startRow,int endRow,int startCol,int shiftNumber,boolean removeSourceMergedRegion){
  Set mergedRegions=new HashSet();
  for (int rowNum=startRow; rowNum <= endRow; rowNum++) {
    HSSFRow row=sheet.getRow(rowNum);
    if (row != null) {
      int lastCellNum=row.getLastCellNum();
      for (int colNum=lastCellNum; colNum >= startCol; colNum--) {
        int destColNum=colNum + shiftNumber;
        HSSFCell destCell=row.getCell(destColNum);
        if (destCell == null) {
          destCell=row.createCell(destColNum);
        }
        HSSFCell cell=row.getCell(colNum);
        if (cell == null) {
          cell=row.createCell(colNum);
        }
        copyCell(cell,destCell,true);
        Util.updateMergedRegionInRow(sheet,mergedRegions,rowNum,colNum,destColNum,removeSourceMergedRegion);
      }
    }
  }
}
Program: 81494
Project: 81494
Buggy source:
private static boolean isNewMergedRegion(CellRangeAddress region,Collection mergedRegions){
  for (Iterator iterator=mergedRegions.iterator(); iterator.hasNext(); ) {
    CellRangeAddress cellRangeAddress=(CellRangeAddress)iterator.next();
    if (areRegionsEqual(cellRangeAddress,region)) {
      return false;
    }
  }
  return true;
}

Fixed version (ground truth):
protected static boolean isNewMergedRegion(CellRangeAddress region,Collection mergedRegions){
  for (Iterator iterator=mergedRegions.iterator(); iterator.hasNext(); ) {
    CellRangeAddress cellRangeAddress=(CellRangeAddress)iterator.next();
    if (areRegionsEqual(cellRangeAddress,region)) {
      return false;
    }
  }
  return true;
}
Program: 81495
Project: 81495
Buggy source:
public static void copyRow(HSSFSheet srcSheet,HSSFSheet destSheet,HSSFRow srcRow,HSSFRow destRow,String expressionToReplace,String expressionReplacement){
  Set mergedRegions=new TreeSet();
  if (srcRow.getHeight() >= 0) {
    destRow.setHeight(srcRow.getHeight());
  }
  for (int j=srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
    HSSFCell oldCell=srcRow.getCell(j);
    HSSFCell newCell=destRow.getCell(j);
    if (oldCell != null) {
      if (newCell == null) {
        newCell=destRow.createCell(j);
      }
      copyCell(oldCell,newCell,true,expressionToReplace,expressionReplacement);
      CellRangeAddress mergedRegion=getMergedRegion(srcSheet,srcRow.getRowNum(),oldCell.getColumnIndex());
      if (mergedRegion != null) {
        CellRangeAddress newMergedRegion=new CellRangeAddress(mergedRegion.getFirstRow(),mergedRegion.getLastRow(),mergedRegion.getFirstColumn(),mergedRegion.getLastColumn());
        if (isNewMergedRegion(newMergedRegion,mergedRegions)) {
          mergedRegions.add(newMergedRegion);
          destSheet.addMergedRegion(newMergedRegion);
        }
      }
    }
  }
}

Fixed version (ground truth):
public static void copyRow(HSSFSheet srcSheet,HSSFSheet destSheet,HSSFRow srcRow,HSSFRow destRow,String expressionToReplace,String expressionReplacement){
  Set mergedRegions=new HashSet();
  if (srcRow.getHeight() >= 0) {
    destRow.setHeight(srcRow.getHeight());
  }
  for (int j=srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
    HSSFCell oldCell=srcRow.getCell(j);
    HSSFCell newCell=destRow.getCell(j);
    if (oldCell != null) {
      if (newCell == null) {
        newCell=destRow.createCell(j);
      }
      copyCell(oldCell,newCell,true,expressionToReplace,expressionReplacement);
      CellRangeAddress mergedRegion=getMergedRegion(srcSheet,srcRow.getRowNum(),oldCell.getColumnIndex());
      if (mergedRegion != null) {
        CellRangeAddress newMergedRegion=new CellRangeAddress(mergedRegion.getFirstRow(),mergedRegion.getLastRow(),mergedRegion.getFirstColumn(),mergedRegion.getLastColumn());
        if (isNewMergedRegion(newMergedRegion,mergedRegions)) {
          mergedRegions.add(newMergedRegion);
          destSheet.addMergedRegion(newMergedRegion);
        }
      }
    }
  }
}
Program: 81497
Project: 81497
Buggy source:
public void testOutTagInOneRow(){
  Map beans=new HashMap();
  List employees=itDepartment.getStaff();
  beans.put("String_Node_Str",employees);
  InputStream is=new BufferedInputStream(getClass().getResourceAsStream(outTagOneRowXLS));
  XLSTransformer transformer=new XLSTransformer();
  transformer.setJexlInnerCollectionsAccess(true);
  HSSFWorkbook resultWorkbook=transformer.transformXLS(is,beans);
  HSSFSheet sheet=resultWorkbook.getSheetAt(0);
  int index=0;
  for (int i=0; i < employees.size(); i++) {
    Employee employee=(Employee)employees.get(i);
    if (employee.getPayment().doubleValue() > 2000) {
      HSSFRow row=sheet.getRow(index);
      index++;
      assertNotNull("String_Node_Str",row);
      assertEquals("String_Node_Str",employee.getName(),row.getCell((short)0).getRichStringCellValue().getString());
      assertEquals("String_Node_Str",employee.getPayment().doubleValue(),row.getCell((short)1).getNumericCellValue(),1e-6);
      assertEquals("String_Node_Str",employee.getBonus().doubleValue(),row.getCell((short)2).getNumericCellValue(),1e-6);
    }
  }
}

Fixed version (ground truth):
public void testOutTagInOneRow() throws IOException {
  Map beans=new HashMap();
  List employees=itDepartment.getStaff();
  beans.put("String_Node_Str",employees);
  InputStream is=new BufferedInputStream(getClass().getResourceAsStream(outTagOneRowXLS));
  XLSTransformer transformer=new XLSTransformer();
  transformer.setJexlInnerCollectionsAccess(true);
  HSSFWorkbook resultWorkbook=transformer.transformXLS(is,beans);
  HSSFSheet sheet=resultWorkbook.getSheetAt(0);
  int index=0;
  for (int i=0; i < employees.size(); i++) {
    Employee employee=(Employee)employees.get(i);
    if (employee.getPayment().doubleValue() > 2000) {
      HSSFRow row=sheet.getRow(index);
      index++;
      assertNotNull("String_Node_Str",row);
      assertEquals("String_Node_Str",employee.getName(),row.getCell((short)0).getRichStringCellValue().getString());
      assertEquals("String_Node_Str",employee.getPayment().doubleValue(),row.getCell((short)1).getNumericCellValue(),1e-6);
      assertEquals("String_Node_Str",employee.getBonus().doubleValue(),row.getCell((short)2).getNumericCellValue(),1e-6);
    }
  }
  is.close();
}
Program: 81498
Project: 81498
Buggy source:
private String parseAggregate(String expr){
  int i=expr.indexOf("String_Node_Str");
  if (i >= 0) {
    String aggregate=expr.substring(0,i);
    if (aggregate.length() == 0) {
      aggregateFunction=null;
      aggregateField=null;
    }
 else {
      int f1=aggregate.indexOf("String_Node_Str");
      int f2=aggregate.indexOf("String_Node_Str");
      if (f1 != -1 && f2 != -1 && f2 > f1) {
        aggregateFunction=aggregate.substring(0,f1);
        aggregateField=aggregate.substring(f1 + 1,f2);
      }
 else {
        aggregateFunction=aggregate;
        aggregateField="String_Node_Str";
      }
    }
    return expr.substring(i + 1);
  }
  aggregateFunction=null;
  aggregateField=null;
  return expr;
}

Fixed version (ground truth):
private String parseAggregate(String expr){
  String[] aggregateParts=expr.split(aggregateSeparator,2);
  int i=expr.indexOf("String_Node_Str");
  if (aggregateParts.length >= 2 && i >= 0) {
    String aggregate=expr.substring(0,i);
    if (aggregate.length() == 0) {
      aggregateFunction=null;
      aggregateField=null;
    }
 else {
      int f1=aggregate.indexOf("String_Node_Str");
      int f2=aggregate.indexOf("String_Node_Str");
      if (f1 != -1 && f2 != -1 && f2 > f1) {
        aggregateFunction=aggregate.substring(0,f1);
        aggregateField=aggregate.substring(f1 + 1,f2);
      }
 else {
        aggregateFunction=aggregate;
        aggregateField="String_Node_Str";
      }
    }
    return expr.substring(i + 1);
  }
  aggregateFunction=null;
  aggregateField=null;
  return expr;
}
Program: 81499
Project: 81499
Buggy source:
protected void setUp() throws Exception {
  Class.forName("String_Node_Str");
  conn=DriverManager.getConnection("String_Node_Str","String_Node_Str","String_Node_Str");
  Statement stmt=conn.createStatement();
  stmt.executeUpdate(CREATE_DEPARTMENT_TABLE);
  stmt.executeUpdate(CREATE_EMPLOYEE_TABLE);
  PreparedStatement insertDep=conn.prepareStatement(INSERT_DEPARTMENT);
  PreparedStatement insertStmt=conn.prepareStatement(INSERT_EMPLOYEE);
  int k=1;
  int n=1;
  for (int i=0; i < depNames.length; i++) {
    String depName=depNames[i];
    insertDep.setString(1,depName);
    insertDep.setInt(2,n++);
    insertDep.executeUpdate();
    for (int j=0; j < employeeNames[i].length; j++) {
      insertStmt.setString(1,employeeNames[i][j]);
      insertStmt.setInt(2,employeeAges[i][j]);
      insertStmt.setDouble(3,employeePayments[i][j]);
      insertStmt.setDouble(4,employeeBonuses[i][j]);
      SimpleDateFormat sdf=new SimpleDateFormat("String_Node_Str");
      insertStmt.setDate(5,new Date(sdf.parse(employeeBirthDates[i][j]).getTime()));
      insertStmt.setInt(6,n - 1);
      insertStmt.setInt(7,k++);
      insertStmt.executeUpdate();
    }
  }
  stmt.close();
  insertStmt.close();
}

Fixed version (ground truth):
protected void setUp() throws Exception {
  Class.forName("String_Node_Str");
  conn=DriverManager.getConnection("String_Node_Str","String_Node_Str","String_Node_Str");
  Statement stmt=conn.createStatement();
  stmt.executeUpdate(CREATE_DEPARTMENT_TABLE);
  stmt.executeUpdate(CREATE_EMPLOYEE_TABLE);
  PreparedStatement insertDep=conn.prepareStatement(INSERT_DEPARTMENT);
  PreparedStatement insertStmt=conn.prepareStatement(INSERT_EMPLOYEE);
  int k=1;
  int n=1;
  for (int i=0; i < depNames.length; i++) {
    String depName=depNames[i];
    insertDep.setString(1,depName);
    insertDep.setInt(2,n++);
    insertDep.executeUpdate();
    for (int j=0; j < employeeNames[i].length; j++) {
      insertStmt.setString(1,employeeNames[i][j]);
      insertStmt.setInt(2,employeeAges[i][j]);
      insertStmt.setDouble(3,employeePayments[i][j]);
      insertStmt.setDouble(4,employeeBonuses[i][j]);
      SimpleDateFormat sdf=new SimpleDateFormat("String_Node_Str");
      insertStmt.setDate(5,new Date(sdf.parse(employeeBirthDates[i][j]).getTime()));
      SimpleDateFormat tdf=new SimpleDateFormat("String_Node_Str");
      insertStmt.setTimestamp(6,new Timestamp(tdf.parse(birthTimestamps[i][j]).getTime()));
      insertStmt.setInt(7,n - 1);
      insertStmt.setInt(8,k++);
      insertStmt.executeUpdate();
    }
  }
  stmt.close();
  insertStmt.close();
}
Program: 81500
Project: 81500
Buggy source:
public Set findRefCells(){
  Set refCells=new HashSet();
  for (Iterator iterator=formulaParts.iterator(); iterator.hasNext(); ) {
    FormulaPart formulaPart=(FormulaPart)iterator.next();
    refCells.addAll(formulaPart.findRefCells());
  }
  return refCells;
}

Fixed version (ground truth):
public Set findRefCells(){
  Set refCells=new HashSet();
  for (Iterator iterator=formulaParts.iterator(); iterator.hasNext(); ) {
    FormulaPart formulaPart=(FormulaPart)iterator.next();
    refCells.addAll(formulaPart.getRefCells());
  }
  return refCells;
}
Program: 81501
Project: 81501
Buggy source:
public FormulaPart(FormulaPart aFormulaPart){
  this.parentFormula=aFormulaPart.parentFormula;
  for (int i=0; i < aFormulaPart.parts.size(); i++) {
    Object part=aFormulaPart.parts.get(i);
    if (part instanceof String) {
      parts.add(part.toString());
    }
 else     if (part instanceof CellRef) {
      CellRef cellRef=new CellRef(part.toString(),this);
      parts.add(cellRef);
      cellRefs.add(cellRef);
    }
  }
}

Fixed version (ground truth):
public FormulaPart(FormulaPart aFormulaPart){
  this.parentFormula=aFormulaPart.parentFormula;
  for (int i=0; i < aFormulaPart.parts.size(); i++) {
    Object part=aFormulaPart.parts.get(i);
    if (part instanceof String) {
      parts.add(part.toString());
    }
 else     if (part instanceof CellRef) {
      CellRef cellRef=new CellRef(part.toString(),this);
      parts.add(cellRef);
      cellRefs.add(cellRef);
    }
  }
  this.defaultValue=aFormulaPart.defaultValue;
}
Program: 81502
Project: 81502
Buggy source:
public void removeCellRefs(Set cellRefsToRemove){
  List formulaPartIndexesToRemove=new ArrayList();
  Object prevFormulaPart=null;
  Object nextFormulaPart=null;
  for (int i=0; i < parts.size(); i++) {
    Object formulaPart=parts.get(i);
    if (cellRefsToRemove.contains(formulaPart)) {
      formulaPartIndexesToRemove.add(new Integer(i));
      if (i > 0) {
        prevFormulaPart=parts.get(i - 1);
      }
      if (i < parts.size() - 1) {
        nextFormulaPart=parts.get(i + 1);
      }
 else {
        nextFormulaPart=null;
      }
      if (prevFormulaPart != null) {
        if (prevFormulaPart.toString().equals("String_Node_Str")) {
          formulaPartIndexesToRemove.add(new Integer(i - 1));
        }
 else         if (nextFormulaPart != null && nextFormulaPart.toString().equals("String_Node_Str")) {
          formulaPartIndexesToRemove.add(new Integer(i + 1));
        }
      }
    }
  }
  int shift=0;
  for (int i=0; i < formulaPartIndexesToRemove.size(); i++) {
    int index=((Integer)formulaPartIndexesToRemove.get(i)).intValue();
    parts.remove(index - shift);
    shift++;
  }
  cellRefs.removeAll(cellRefsToRemove);
}

Fixed version (ground truth):
public void removeCellRefs(Set cellRefsToRemove){
  List formulaPartIndexesToRemove=new ArrayList();
  Object prevFormulaPart=null;
  Object nextFormulaPart;
  for (int i=0; i < parts.size(); i++) {
    Object formulaPart=parts.get(i);
    if (cellRefsToRemove.contains(formulaPart)) {
      formulaPartIndexesToRemove.add(new Integer(i));
      if (i > 0) {
        prevFormulaPart=parts.get(i - 1);
      }
      if (i < parts.size() - 1) {
        nextFormulaPart=parts.get(i + 1);
      }
 else {
        nextFormulaPart=null;
      }
      if (prevFormulaPart != null) {
        if (prevFormulaPart.toString().equals("String_Node_Str")) {
          formulaPartIndexesToRemove.add(new Integer(i - 1));
        }
 else         if (nextFormulaPart != null && nextFormulaPart.toString().equals("String_Node_Str")) {
          formulaPartIndexesToRemove.add(new Integer(i + 1));
        }
      }
    }
  }
  Collections.sort(formulaPartIndexesToRemove);
  int shift=0;
  for (int i=0; i < formulaPartIndexesToRemove.size(); i++) {
    int index=((Integer)formulaPartIndexesToRemove.get(i)).intValue();
    parts.remove(index - shift);
    shift++;
  }
  cellRefs.removeAll(cellRefsToRemove);
}
Program: 81503
Project: 81503
Buggy source:
public CellRef(String cellRef,Formula parentFormula){
  this(cellRef);
  this.parentFormula=parentFormula;
}

Fixed version (ground truth):
public CellRef(String cellRef,FormulaPart parentFormula){
  this(cellRef);
  this.parentFormula=parentFormula;
}
Program: 81504
Project: 81504
Buggy source:
public boolean containsListRanges(){
  return formula.indexOf(formulaListRangeToken) >= 0;
}

Fixed version (ground truth):
public boolean containsListRanges(){
  return formula.matches("String_Node_Str");
}
Program: 81505
Project: 81505
Buggy source:
public Formula(Formula f){
  this.formula=f.formula;
  this.sheet=f.getSheet();
  for (int i=0; i < f.formulaParts.size(); i++) {
    Object formulaPart=f.formulaParts.get(i);
    if (formulaPart instanceof String) {
      formulaParts.add(formulaPart.toString());
    }
 else     if (formulaPart instanceof CellRef) {
      CellRef cellRef=new CellRef(formulaPart.toString(),this);
      formulaParts.add(cellRef);
      cellRefs.add(cellRef);
    }
  }
}

Fixed version (ground truth):
public Formula(Formula f){
  this.formula=f.formula;
  this.sheet=f.getSheet();
  for (int i=0; i < f.formulaParts.size(); i++) {
    FormulaPart formulaPart=(FormulaPart)f.formulaParts.get(i);
    formulaParts.add(new FormulaPart(formulaPart));
  }
  updateCellRefs();
}
Program: 81506
Project: 81506
Buggy source:
public Set findRefCells(){
  Set refCells=new HashSet();
  Matcher refCellMatcher=regexCellRefPattern.matcher(formula);
  while (refCellMatcher.find()) {
    refCells.add(refCellMatcher.group());
  }
  return refCells;
}

Fixed version (ground truth):
public Set findRefCells(){
  Set refCells=new HashSet();
  for (Iterator iterator=formulaParts.iterator(); iterator.hasNext(); ) {
    FormulaPart formulaPart=(FormulaPart)iterator.next();
    refCells.addAll(formulaPart.findRefCells());
  }
  return refCells;
}
Program: 81507
Project: 81507
Buggy source:
public void removeCellRefs(Set cellRefsToRemove){
  List formulaPartIndexesToRemove=new ArrayList();
  Object prevFormulaPart=null;
  Object nextFormulaPart=null;
  for (int i=0; i < formulaParts.size(); i++) {
    Object formulaPart=formulaParts.get(i);
    if (cellRefsToRemove.contains(formulaPart)) {
      formulaPartIndexesToRemove.add(new Integer(i));
      if (i > 0) {
        prevFormulaPart=formulaParts.get(i - 1);
      }
      if (i < formulaParts.size() - 1) {
        nextFormulaPart=formulaParts.get(i + 1);
      }
 else {
        nextFormulaPart=null;
      }
      if (prevFormulaPart != null) {
        if (prevFormulaPart.toString().equals("String_Node_Str")) {
          formulaPartIndexesToRemove.add(new Integer(i - 1));
        }
 else         if (nextFormulaPart != null && nextFormulaPart.toString().equals("String_Node_Str")) {
          formulaPartIndexesToRemove.add(new Integer(i + 1));
        }
      }
    }
  }
  int shift=0;
  for (int i=0; i < formulaPartIndexesToRemove.size(); i++) {
    int index=((Integer)formulaPartIndexesToRemove.get(i)).intValue();
    formulaParts.remove(index - shift);
    shift++;
  }
  cellRefs.removeAll(cellRefsToRemove);
}

Fixed version (ground truth):
public void removeCellRefs(Set cellRefsToRemove){
  for (int i=0; i < formulaParts.size(); i++) {
    FormulaPart formulaPart=(FormulaPart)formulaParts.get(i);
    formulaPart.removeCellRefs(cellRefsToRemove);
  }
  updateCellRefs();
}
Program: 81508
Project: 81508
Buggy source:
public String getActualFormula(){
  Object formulaPart;
  String actualFormula="String_Node_Str";
  for (Iterator iterator=formulaParts.iterator(); iterator.hasNext(); ) {
    formulaPart=iterator.next();
    actualFormula+=formulaPart.toString();
  }
  return actualFormula;
}

Fixed version (ground truth):
public String getActualFormula(){
  FormulaPart formulaPart;
  String actualFormula="String_Node_Str";
  for (Iterator iterator=formulaParts.iterator(); iterator.hasNext(); ) {
    formulaPart=(FormulaPart)iterator.next();
    actualFormula+=formulaPart.getActualFormula();
  }
  return actualFormula;
}
Program: 81509
Project: 81509
Buggy source:
public void updateReplacedRefCellsCollection(){
  CellRef cellRef;
  for (int i=0, size=cellRefsToRemove.size(); i < size; i++) {
    cellRef=(CellRef)cellRefsToRemove.get(i);
    cellRefs.remove(cellRef);
  }
  cellRefsToRemove.clear();
  Object cellRef2;
  for (int i=0, size=cellRefsToAdd.size(); i < size; i++) {
    cellRef2=cellRefsToAdd.get(i);
    cellRefs.add(cellRef2);
  }
  cellRefsToAdd.clear();
}

Fixed version (ground truth):
public void updateReplacedRefCellsCollection(){
  for (Iterator iterator=formulaParts.iterator(); iterator.hasNext(); ) {
    FormulaPart formulaPart=(FormulaPart)iterator.next();
    formulaPart.updateReplacedRefCellsCollection();
  }
}
Program: 81510
Project: 81510
Buggy source:
public void parseFormula(){
  formulaParts.clear();
  cellRefs.clear();
  Matcher refCellMatcher=regexCellRefPattern.matcher(formula);
  int end=0;
  CellRef cellRef=null;
  while (refCellMatcher.find()) {
    String formulaPart=formula.substring(end,refCellMatcher.start());
    formulaPart=adjustFormulaPartForCellIndex(cellRef,formulaPart);
    formulaParts.add(formulaPart);
    cellRef=new CellRef(refCellMatcher.group(),this);
    formulaParts.add(cellRef);
    cellRefs.add(cellRef);
    end=refCellMatcher.end();
  }
  formulaParts.add(adjustFormulaPartForCellIndex(cellRef,formula.substring(end)));
}

Fixed version (ground truth):
public void parseFormula(){
  formulaParts.clear();
  Matcher formulaPartMatcher=regexFormulaPartPattern.matcher(formula);
  int end=0;
  while (formulaPartMatcher.find()) {
    String formulaPartString=formula.substring(end,formulaPartMatcher.start());
    if (formulaPartString.length() > 0) {
      formulaParts.add(new FormulaPart(formulaPartString,this));
    }
    formulaParts.add(new FormulaPart(formulaPartMatcher.group(),this));
    end=formulaPartMatcher.end();
  }
  String endPart=formula.substring(end);
  if (endPart.length() > 0) {
    formulaParts.add(new FormulaPart(endPart,this));
  }
  updateCellRefs();
}
Program: 81512
Project: 81512
Buggy source:
static void clearRowCells(HSSFRow row,short startCell,short endCell){
  if (row != null) {
    for (short i=startCell; i <= endCell; i++) {
      HSSFCell cell=row.getCell(i);
      clearCell(cell);
    }
  }
}

Fixed version (ground truth):
static void clearRowCells(HSSFRow row,short startCell,short endCell){
  if (row != null) {
    for (short i=startCell; i <= endCell; i++) {
      HSSFCell cell=row.getCell(i);
      row.removeCell(cell);
      row.createCell(i);
    }
  }
}
Program: 81513
Project: 81513
Buggy source:
private Object getCellValue(HSSFCell cell,Object obj){
  Object value=null;
  if (obj instanceof String) {
    value=cell.getStringCellValue() != null ? cell.getStringCellValue().trim() : null;
  }
 else   if (obj instanceof Double) {
    value=new Double(cell.getNumericCellValue());
  }
 else   if (obj instanceof BigDecimal) {
    value=new BigDecimal(cell.getNumericCellValue());
  }
 else   if (obj instanceof Integer) {
    value=new Integer((int)cell.getNumericCellValue());
  }
 else   if (obj instanceof Float) {
    value=new Float(cell.getNumericCellValue());
  }
 else   if (obj instanceof Date) {
    value=cell.getDateCellValue();
  }
 else   if (obj instanceof Calendar) {
    Calendar c=Calendar.getInstance();
    c.setTime(cell.getDateCellValue());
    value=c;
  }
 else   if (obj instanceof Boolean) {
    if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
      value=(cell.getBooleanCellValue()) ? Boolean.TRUE : Boolean.FALSE;
    }
 else     if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
      value=Boolean.valueOf(cell.getStringCellValue());
    }
 else {
      value=Boolean.FALSE;
    }
  }
  return value;
}

Fixed version (ground truth):
private Object getCellValue(HSSFCell cell,Object obj){
  Object value=null;
  if (obj instanceof String) {
    value=readStringValue(cell);
  }
 else   if (obj instanceof Double) {
    value=new Double(cell.getNumericCellValue());
  }
 else   if (obj instanceof BigDecimal) {
    value=new BigDecimal(cell.getNumericCellValue());
  }
 else   if (obj instanceof Integer) {
    value=new Integer((int)cell.getNumericCellValue());
  }
 else   if (obj instanceof Float) {
    value=new Float(cell.getNumericCellValue());
  }
 else   if (obj instanceof Date) {
    value=cell.getDateCellValue();
  }
 else   if (obj instanceof Calendar) {
    Calendar c=Calendar.getInstance();
    c.setTime(cell.getDateCellValue());
    value=c;
  }
 else   if (obj instanceof Boolean) {
    if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
      value=(cell.getBooleanCellValue()) ? Boolean.TRUE : Boolean.FALSE;
    }
 else     if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
      value=Boolean.valueOf(cell.getStringCellValue());
    }
 else {
      value=Boolean.FALSE;
    }
  }
  return value;
}
Program: 81514
Project: 81514
Buggy source:
private Object getCellValue(HSSFCell cell,Class type){
  if (cell == null) {
    return null;
  }
  Object value=null;
  if (isDate(type)) {
    value=cell.getDateCellValue();
  }
 else {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
      value=cell.getStringCellValue();
    break;
case HSSFCell.CELL_TYPE_NUMERIC:
  value=new Double(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
value=(cell.getBooleanCellValue()) ? Boolean.TRUE : Boolean.FALSE;
break;
case HSSFCell.CELL_TYPE_BLANK:
break;
case HSSFCell.CELL_TYPE_ERROR:
break;
case HSSFCell.CELL_TYPE_FORMULA:
break;
default :
break;
}
}
return value;
}

Fixed version (ground truth):
private Object getCellValue(HSSFCell cell,Class type){
  if (cell == null) {
    return null;
  }
  Object value=null;
  if (isDate(type)) {
    value=cell.getDateCellValue();
  }
 else {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
      value=cell.getStringCellValue();
    break;
case HSSFCell.CELL_TYPE_NUMERIC:
  value=new Double(cell.getNumericCellValue());
if (!type.isInstance(value)) {
  double doubleValue=((Double)value).doubleValue();
  if (Math.floor(doubleValue) == doubleValue) {
    value=Long.toString(((Double)value).longValue());
  }
 else {
    value=value.toString();
  }
}
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
value=(cell.getBooleanCellValue()) ? Boolean.TRUE : Boolean.FALSE;
break;
case HSSFCell.CELL_TYPE_BLANK:
break;
case HSSFCell.CELL_TYPE_ERROR:
break;
case HSSFCell.CELL_TYPE_FORMULA:
break;
default :
break;
}
}
return value;
}
Program: 81516
Project: 81516
Buggy source:
public static void copyRow(HSSFSheet srcSheet,HSSFSheet destSheet,HSSFRow srcRow,HSSFRow destRow){
  Set mergedRegions=new TreeSet();
  destRow.setHeight(srcRow.getHeight());
  for (short j=srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
    HSSFCell oldCell=srcRow.getCell(j);
    HSSFCell newCell=destRow.getCell(j);
    if (oldCell != null) {
      if (newCell == null) {
        newCell=destRow.createCell(j);
      }
      copyCell(oldCell,newCell,true);
      Region mergedRegion=getMergedRegion(srcSheet,srcRow.getRowNum(),oldCell.getCellNum());
      if (mergedRegion != null) {
        Region newMergedRegion=new Region(mergedRegion.getRowFrom(),mergedRegion.getColumnFrom(),mergedRegion.getRowTo(),mergedRegion.getColumnTo());
        if (isNewMergedRegion(newMergedRegion,mergedRegions)) {
          mergedRegions.add(newMergedRegion);
          destSheet.addMergedRegion(newMergedRegion);
        }
      }
    }
  }
}

Fixed version (ground truth):
public static void copyRow(HSSFSheet srcSheet,HSSFSheet destSheet,HSSFRow srcRow,HSSFRow destRow,String expressionToReplace,String expressionReplacement){
  Set mergedRegions=new TreeSet();
  destRow.setHeight(srcRow.getHeight());
  for (short j=srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
    HSSFCell oldCell=srcRow.getCell(j);
    HSSFCell newCell=destRow.getCell(j);
    if (oldCell != null) {
      if (newCell == null) {
        newCell=destRow.createCell(j);
      }
      copyCell(oldCell,newCell,true,expressionToReplace,expressionReplacement);
      Region mergedRegion=getMergedRegion(srcSheet,srcRow.getRowNum(),oldCell.getCellNum());
      if (mergedRegion != null) {
        Region newMergedRegion=new Region(mergedRegion.getRowFrom(),mergedRegion.getColumnFrom(),mergedRegion.getRowTo(),mergedRegion.getColumnTo());
        if (isNewMergedRegion(newMergedRegion,mergedRegions)) {
          mergedRegions.add(newMergedRegion);
          destSheet.addMergedRegion(newMergedRegion);
        }
      }
    }
  }
}
Program: 81517
Project: 81517
Buggy source:
public static void copyCell(HSSFCell oldCell,HSSFCell newCell,boolean copyStyle){
  if (copyStyle) {
    newCell.setCellStyle(oldCell.getCellStyle());
  }
  newCell.setEncoding(oldCell.getEncoding());
switch (oldCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
    newCell.setCellValue(oldCell.getStringCellValue());
  break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default :
break;
}
}

Fixed version (ground truth):
public static void copyCell(HSSFCell oldCell,HSSFCell newCell,boolean copyStyle,String expressionToReplace,String expressionReplacement){
  if (copyStyle) {
    newCell.setCellStyle(oldCell.getCellStyle());
  }
  newCell.setEncoding(oldCell.getEncoding());
switch (oldCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
    String oldValue=oldCell.getStringCellValue();
  newCell.setCellValue(oldValue != null ? oldValue.replaceAll(expressionToReplace,expressionReplacement) : null);
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default :
break;
}
}
Program: 81518
Project: 81518
Buggy source:
public static void copySheets(HSSFSheet newSheet,HSSFSheet sheet){
  int maxColumnNum=0;
  for (int i=sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
    HSSFRow srcRow=sheet.getRow(i);
    HSSFRow destRow=newSheet.createRow(i);
    if (srcRow != null) {
      Util.copyRow(sheet,newSheet,srcRow,destRow);
      if (srcRow.getLastCellNum() > maxColumnNum) {
        maxColumnNum=srcRow.getLastCellNum();
      }
    }
  }
  for (short i=0; i <= maxColumnNum; i++) {
    newSheet.setColumnWidth(i,sheet.getColumnWidth(i));
  }
}

Fixed version (ground truth):
public static void copySheets(HSSFSheet newSheet,HSSFSheet sheet,String expressionToReplace,String expressionReplacement){
  int maxColumnNum=0;
  for (int i=sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
    HSSFRow srcRow=sheet.getRow(i);
    HSSFRow destRow=newSheet.createRow(i);
    if (srcRow != null) {
      Util.copyRow(sheet,newSheet,srcRow,destRow,expressionToReplace,expressionReplacement);
      if (srcRow.getLastCellNum() > maxColumnNum) {
        maxColumnNum=srcRow.getLastCellNum();
      }
    }
  }
  for (short i=0; i <= maxColumnNum; i++) {
    newSheet.setColumnWidth(i,sheet.getColumnWidth(i));
  }
}