Program: 86757
Project: 86757
Buggy source:
/** 
 * Adds in a Row to the given Sheet
 */
public Row addRow(Workbook wb,SheetToAdd sheetToAdd,RowToAdd rowToAdd,int rowIndex,ReportData reportData,ReportDesign design,Map<String,String> repeatSections){
  Row newRow=sheetToAdd.getSheet().createRow(rowIndex);
  Row rowToClone=rowToAdd.getRowToClone();
  try {
    CellStyle rowStyle=rowToClone.getRowStyle();
    if (rowStyle != null) {
      newRow.setRowStyle(rowStyle);
    }
  }
 catch (  Exception e) {
  }
  newRow.setHeight(rowToClone.getHeight());
  List<CellToAdd> cellsToAdd=new ArrayList<CellToAdd>();
  int totalCells=rowToClone.getPhysicalNumberOfCells();
  int cellsFound=0;
  for (int cellNum=0; cellsFound < totalCells; cellNum++) {
    Cell currentCell=rowToClone.getCell(cellNum);
    log.debug("String_Node_Str" + currentCell);
    if (currentCell != null) {
      cellsFound++;
    }
    String repeatingColumnProperty=getRepeatingColumnProperty(sheetToAdd.getOriginalSheetNum(),cellNum,repeatSections);
    if (repeatingColumnProperty != null) {
      String[] dataSetSpanSplit=repeatingColumnProperty.split("String_Node_Str");
      String dataSetName=dataSetSpanSplit[0];
      DataSet dataSet=getDataSet(reportData,dataSetName,rowToAdd.getReplacementData());
      int numCellsToRepeat=1;
      if (dataSetSpanSplit.length == 2) {
        numCellsToRepeat=Integer.parseInt(dataSetSpanSplit[1]);
      }
      log.debug("String_Node_Str" + dataSet + "String_Node_Str"+ numCellsToRepeat);
      int repeatNum=0;
      for (      DataSetRow dataSetRow : dataSet) {
        repeatNum++;
        for (int i=0; i < numCellsToRepeat; i++) {
          Cell cell=(i == 0 ? currentCell : rowToClone.getCell(cellNum + i));
          if (repeatNum == 1 && cell != null && cell != currentCell) {
            cellsFound++;
          }
          Map<String,Object> newReplacements=getReplacementData(rowToAdd.getReplacementData(),reportData,design,dataSetName,dataSetRow,repeatNum);
          cellsToAdd.add(new CellToAdd(cell,newReplacements));
          log.debug("String_Node_Str" + cell + "String_Node_Str"+ dataSetRow);
        }
      }
      cellNum+=numCellsToRepeat;
    }
 else {
      cellsToAdd.add(new CellToAdd(currentCell,rowToAdd.getReplacementData()));
      log.debug("String_Node_Str" + currentCell);
    }
  }
  String prefix=getExpressionPrefix(design);
  String suffix=getExpressionSuffix(design);
  for (int i=0; i < cellsToAdd.size(); i++) {
    CellToAdd cellToAdd=cellsToAdd.get(i);
    Cell newCell=newRow.createCell(i);
    Cell cellToClone=cellToAdd.getCellToClone();
    if (cellToClone != null) {
      Object contents=ExcelUtil.getCellContents(cellToClone);
      newCell.setCellStyle(cellToClone.getCellStyle());
      try {
        newCell.setCellFormula(cellToClone.getCellFormula());
      }
 catch (      Exception e) {
      }
      int numFormattings=sheetToAdd.getSheet().getSheetConditionalFormatting().getNumConditionalFormattings();
      for (int n=0; n < numFormattings; n++) {
        ConditionalFormatting f=sheetToAdd.getSheet().getSheetConditionalFormatting().getConditionalFormattingAt(n);
        for (        CellRangeAddress add : f.getFormattingRanges()) {
          if (add.getFirstRow() == rowToAdd.getRowToClone().getRowNum() && add.getLastRow() == rowToClone.getRowNum()) {
            if (add.getFirstColumn() == cellToClone.getColumnIndex() && add.getLastColumn() == cellToClone.getColumnIndex()) {
              ConditionalFormattingRule[] rules=new ConditionalFormattingRule[f.getNumberOfRules()];
              for (int j=0; j < f.getNumberOfRules(); j++) {
                rules[j]=f.getRule(j);
              }
              CellRangeAddress[] cellRange=new CellRangeAddress[1];
              cellRange[0]=new CellRangeAddress(rowIndex,rowIndex,i,i);
              sheetToAdd.getSheet().getSheetConditionalFormatting().addConditionalFormatting(cellRange,rules);
            }
          }
        }
      }
      if (ObjectUtil.notNull(contents)) {
        if (contents instanceof String) {
          contents=EvaluationUtil.evaluateExpression(contents.toString(),cellToAdd.getReplacementData(),prefix,suffix);
        }
        ExcelUtil.setCellContents(newCell,contents);
      }
    }
  }
  return newRow;
}

Fixed version (ground truth):
/** 
 * Adds in a Row to the given Sheet
 */
public Row addRow(Workbook wb,SheetToAdd sheetToAdd,RowToAdd rowToAdd,int rowIndex,ReportData reportData,ReportDesign design,Map<String,String> repeatSections){
  Row newRow=sheetToAdd.getSheet().createRow(rowIndex);
  Row rowToClone=rowToAdd.getRowToClone();
  try {
    CellStyle rowStyle=rowToClone.getRowStyle();
    if (rowStyle != null) {
      newRow.setRowStyle(rowStyle);
    }
  }
 catch (  Exception e) {
  }
  newRow.setHeight(rowToClone.getHeight());
  List<CellToAdd> cellsToAdd=new ArrayList<CellToAdd>();
  int totalCells=rowToClone.getPhysicalNumberOfCells();
  int cellsFound=0;
  for (int cellNum=0; cellsFound < totalCells; cellNum++) {
    Cell currentCell=rowToClone.getCell(cellNum);
    log.debug("String_Node_Str" + currentCell);
    if (currentCell != null) {
      cellsFound++;
    }
    String repeatingColumnProperty=getRepeatingColumnProperty(sheetToAdd.getOriginalSheetNum(),cellNum,repeatSections);
    if (repeatingColumnProperty != null) {
      String[] dataSetSpanSplit=repeatingColumnProperty.split("String_Node_Str");
      String dataSetName=dataSetSpanSplit[0];
      DataSet dataSet=getDataSet(reportData,dataSetName,rowToAdd.getReplacementData());
      int numCellsToRepeat=1;
      if (dataSetSpanSplit.length == 2) {
        numCellsToRepeat=Integer.parseInt(dataSetSpanSplit[1]);
      }
      log.debug("String_Node_Str" + dataSet + "String_Node_Str"+ numCellsToRepeat);
      int repeatNum=0;
      for (      DataSetRow dataSetRow : dataSet) {
        repeatNum++;
        for (int i=0; i < numCellsToRepeat; i++) {
          Cell cell=(i == 0 ? currentCell : rowToClone.getCell(cellNum + i));
          if (repeatNum == 1 && cell != null && cell != currentCell) {
            cellsFound++;
          }
          Map<String,Object> newReplacements=getReplacementData(rowToAdd.getReplacementData(),reportData,design,dataSetName,dataSetRow,repeatNum);
          cellsToAdd.add(new CellToAdd(cell,newReplacements));
          log.debug("String_Node_Str" + cell + "String_Node_Str"+ dataSetRow);
        }
      }
      cellNum+=numCellsToRepeat;
    }
 else {
      cellsToAdd.add(new CellToAdd(currentCell,rowToAdd.getReplacementData()));
      log.debug("String_Node_Str" + currentCell);
    }
  }
  String prefix=getExpressionPrefix(design);
  String suffix=getExpressionSuffix(design);
  List<CellRangeAddress> newMergedRegions=new ArrayList<CellRangeAddress>();
  for (int i=0; i < cellsToAdd.size(); i++) {
    CellToAdd cellToAdd=cellsToAdd.get(i);
    Cell newCell=newRow.createCell(i);
    Cell cellToClone=cellToAdd.getCellToClone();
    if (cellToClone != null) {
      Object contents=ExcelUtil.getCellContents(cellToClone);
      newCell.setCellStyle(cellToClone.getCellStyle());
      try {
        newCell.setCellFormula(cellToClone.getCellFormula());
      }
 catch (      Exception e) {
      }
      int numFormattings=sheetToAdd.getSheet().getSheetConditionalFormatting().getNumConditionalFormattings();
      for (int n=0; n < numFormattings; n++) {
        ConditionalFormatting f=sheetToAdd.getSheet().getSheetConditionalFormatting().getConditionalFormattingAt(n);
        for (        CellRangeAddress add : f.getFormattingRanges()) {
          if (add.getFirstRow() == rowToAdd.getRowToClone().getRowNum() && add.getLastRow() == rowToClone.getRowNum()) {
            if (add.getFirstColumn() == cellToClone.getColumnIndex() && add.getLastColumn() == cellToClone.getColumnIndex()) {
              ConditionalFormattingRule[] rules=new ConditionalFormattingRule[f.getNumberOfRules()];
              for (int j=0; j < f.getNumberOfRules(); j++) {
                rules[j]=f.getRule(j);
              }
              CellRangeAddress[] cellRange=new CellRangeAddress[1];
              cellRange[0]=new CellRangeAddress(rowIndex,rowIndex,i,i);
              sheetToAdd.getSheet().getSheetConditionalFormatting().addConditionalFormatting(cellRange,rules);
            }
          }
        }
      }
      int numMergedRegions=sheetToAdd.getSheet().getNumMergedRegions();
      for (int n=0; n < numMergedRegions; n++) {
        CellRangeAddress add=sheetToAdd.getSheet().getMergedRegion(n);
        int rowNum=rowToClone.getRowNum();
        if (add.getFirstRow() == rowNum && add.getLastRow() == rowNum) {
          if (add.getFirstColumn() == cellToClone.getColumnIndex()) {
            newMergedRegions.add(new CellRangeAddress(rowNum,rowNum,i,i + add.getNumberOfCells() - 1));
          }
        }
      }
      if (ObjectUtil.notNull(contents)) {
        if (contents instanceof String) {
          contents=EvaluationUtil.evaluateExpression(contents.toString(),cellToAdd.getReplacementData(),prefix,suffix);
        }
        ExcelUtil.setCellContents(newCell,contents);
      }
    }
  }
  for (  CellRangeAddress mergedRegion : newMergedRegions) {
    sheetToAdd.getSheet().addMergedRegion(mergedRegion);
  }
  return newRow;
}