Bug 51273 - ArrayIndexOutOfBoundsException in FormulaCellCacheEntrySet
ArrayIndexOutOfBoundsException in FormulaCellCacheEntrySet
Status: RESOLVED FIXED
Product: POI
Classification: Unclassified
Component: HSSF
3.8-dev
Other Linux
: P2 normal (vote)
: ---
Assigned To: POI Developers List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2011-05-26 16:58 UTC by Alex Mountney
Modified: 2011-05-27 11:46 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Mountney 2011-05-26 16:58:36 UTC
java.lang.ArrayIndexOutOfBoundsException: -2
        at org.apache.poi.ss.formula.FormulaCellCacheEntrySet.addInternal(FormulaCellCacheEntrySet.java:83)
        at org.apache.poi.ss.formula.FormulaCellCacheEntrySet.add(FormulaCellCacheEntrySet.java:72)
        at org.apache.poi.ss.formula.CellCacheEntry.addConsumingCell(CellCacheEntry.java:85)
        at org.apache.poi.ss.formula.FormulaCellCacheEntry.changeConsumingCells(FormulaCellCacheEntry.java:80)
        at org.apache.poi.ss.formula.FormulaCellCacheEntry.setSensitiveInputCells(FormulaCellCacheEntry.java:60)
        at org.apache.poi.ss.formula.FormulaCellCacheEntry.updateFormulaResult(FormulaCellCacheEntry.java:109)
        at org.apache.poi.ss.formula.CellEvaluationFrame.updateFormulaResult(CellEvaluationFrame.java:75)
        at org.apache.poi.ss.formula.EvaluationTracker.updateCacheResult(EvaluationTracker.java:94)
        at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:286)
        at org.apache.poi.ss.formula.WorkbookEvaluator.evaluate(WorkbookEvaluator.java:221)
        at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluateFormulaCellValue(HSSFFormulaEvaluator.java:320)
        at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluate(HSSFFormulaEvaluator.java:182)

Appears to occur randomly when calling HSSFFormulaEvaluator.evaluate(Cell cell) more than once on the same cell.

Looking at the FormulaCellCacheEntrySet.java:83:

	int startIx = cce.hashCode() % arr.length;
	for(int i=startIx; i<arr.length; i++) {
	
startIx could be negative hence the ArrayIndexOutOfBoundsException

Workaround: call HSSFFormulaEvaluator.clearAllCachedResultValues() before invoking evaluate on the same cell although suspect there would still be issues in a multithreaded environment.
Comment 1 Nick Burch 2011-05-27 11:46:37 UTC
Should be fixed in r1128268 - looks like there was a missing Math.abs

Note however that if you're updating cells after having done one calculation, you do need to tell the formula evaluator so it can tweak its cache.