*/
public void testResultOutsideRange() {
Workbook wb = new HSSFWorkbook();
Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0);
cell.setCellFormula("D2:D5"); // IF(TRUE,D2:D5,D2) or OFFSET(D2:D5,0,0) would work too
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
CellValue cv;
try {
cv = fe.evaluate(cell);
} catch (IllegalArgumentException e) {
if ("Specified row index (0) is outside the allowed range (1..4)".equals(e.getMessage())) {
throw new AssertionFailedError("Identified bug in result dereferencing");
}
throw new RuntimeException(e);
}
assertEquals(Cell.CELL_TYPE_ERROR, cv.getCellType());
assertEquals(ErrorConstants.ERROR_VALUE, cv.getErrorValue());
// verify circular refs are still detected properly
fe.clearAllCachedResultValues();
cell.setCellFormula("OFFSET(A1,0,0)");
cv = fe.evaluate(cell);
assertEquals(Cell.CELL_TYPE_ERROR, cv.getCellType());
assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cv.getErrorValue());
}