Re: XSSFEvaluationWorkbook.getSheet can throw ArrayIndexOutOfBoundsException
Andreas Reichel <[email protected]> Sat, 30 Oct 2021 20:13:19 +0700
| Newsgroups | gmane.comp.jakarta.poi.user |
|---|---|
| Message-ID | <cf927a9cf279eef9a772e619b20700a089df65bf.camel@manticore-projects.com> |
Greetings Dominik. thanks for the feedback. I actually assumed already a similar thing and it is worth to note that my Workbook is completely code generated (with many sheets and references in between the sheets). However, based on my suspicion I actually created all Sheets and Cells and Formulas first before I create the Evaluator at the very end and run the evaluation. Also, it seems to happen only sporadically: Sometimes it runs through without an exception, sometimes exceptions are thrown. So my next assumption was about a timing/parallelism issue. "Re-Create the Evaluator" at then end alone does not solve this problem, I would investigate clearAllCachedResultValues() and also work on a simplified test. Best regards Andreas On Sat, 2021-10-30 at 14:55 +0200, Dominik Stadler wrote: > Hi, > > I can reproduce it if you keep the instance of the FormulaEvaluator > while > adding more sheets to the workbook between calls to evaluateXXX() as > then > internal caches get confused. > > Workaround is to either create all sheets up-front or re-create the > Evaluator or use clearAllCachedResultValues() to clear caches > whenever > sheets are added. > > Thanks... Dominik. > > On Sat, Oct 30, 2021 at 2:37 PM Dominik Stadler > <[email protected]> > wrote: > > > Hi, > > > > Sounds like a strange case as there is a check right before that > > line > > which should trigger a more specific error message, but somehow it > > is not > > triggered. > > > > Can you create an issue and if possible share a sample workbook > > which > > shows this problem? > > > > Thanks... Dominik. > > > > On Sat, Oct 30, 2021 at 12:20 PM Andreas Reichel < > > [email protected]> wrote: > > > > > Greetings POI team. > > > > > > Using Apache POI 5.0 I would like evaluate all Cells in order to > > > auto- > > > size all columns in all sheets: > > > FormulaEvaluator evaluator = > > > workbook.getCreationHelper().createFormulaEvaluator(); > > > for (int i =0; i<sheetParameters.length; i++) { > > > Â Â Â Sheet sheet = workbook.getSheetAt(i); > > > Â Â Â for (Row r : sheet) { > > > Â Â Â Â Â Â Â for (Cell c : r) { > > > Â Â Â Â Â Â Â Â Â Â Â if (c.getCellType() == CellType.FORMULA) { > > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â try { > > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // this can throw an > > > ArrayIndexOutOfBoundsException > > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // at > > > org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook.getSheet(XSS > > > FEvaluationWorkbook.java:77) > > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â evaluator.evaluateFormulaCell(c); > > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } catch (Exception ignore) { > > > > > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } > > > Â Â Â Â Â Â Â Â Â Â Â } > > > Â Â Â Â Â Â Â } > > > Â Â Â } > > > > > > Â Â Â for (int k=0; k<=CAPTIONS.length; k++) > > > Â Â Â Â Â Â Â sheet.autoSizeColumn(k); > > > } > > > > > > To my surprise this can throw an Exception: > > > > > > java.lang.ArrayIndexOutOfBoundsException: Index 8 out of bounds > > > for > > > length 8 > > > Â Â Â Â Â Â Â at > > > org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook.getSheet(XSS > > > FEvaluationWorkbook.java:77) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.WorkbookEvaluator.getSheet(WorkbookEval > > > uator.java:117) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.SheetRefEvaluator.getSheet(SheetRefEval > > > uator.java:53) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.SheetRefEvaluator.getEvalForCell(SheetR > > > efEvaluator.java:48) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.SheetRangeEvaluator.getEvalForCell(Shee > > > tRangeEvaluator.java:74) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.LazyRefEval.getInnerValueEval(LazyRefEv > > > al.java:39) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.eval.OperandResolver.chooseSingleElemen > > > tFromRef(OperandResolver.java:217) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.eval.OperandResolver.getSingleValue(Ope > > > randResolver.java:67) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.eval.UnaryMinusEval.evaluate(UnaryMinus > > > Eval.java:38) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.functions.Fixed1ArgFunction.evaluate(Fi > > > xed1ArgFunction.java:33) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.OperationEvaluatorFactory.evaluate(Oper > > > ationEvaluatorFactory.java:140) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.WorkbookEvaluator.evaluateFormula(Workb > > > ookEvaluator.java:541) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookE > > > valuator.java:275) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.WorkbookEvaluator.evaluate(WorkbookEval > > > uator.java:216) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.xssf.usermodel.BaseXSSFFormulaEvaluator.evaluateFo > > > rmulaCellValue(BaseXSSFFormulaEvaluator.java:56) > > > Â Â Â Â Â Â Â at > > > org.apache.poi.ss.formula.BaseFormulaEvaluator.evaluateFormulaCel > > > l(BaseFormulaEvaluator.java:184) > > > Â Â Â Â Â Â Â at > > > com.manticore.etl.custom.UBASecurityDetails.buildReport(UBASecuri > > > tyDetails.java:600) > > > Â Â Â Â Â Â Â at > > > com.manticore.etl.custom.UBASecurityDetails.main(UBASecurityDetai > > > ls.java:334) > > > > > > Should I open an Ticket on that or am I doing something wrong? > > > Thanks and warm regards > > > Andreas > > > > > >