Created attachment 27226 [details] PlainCellCache, raise suitable sheet count to 4096 When updating calculations for Workbook having more than 256 sheets, the evaluation cache at some point throws exception: java.lang.IllegalStateException: value changed at org.apache.poi.ss.formula.EvaluationCache.getPlainValueEntry(EvaluationCache.java:144) at org.apache.poi.ss.formula.EvaluationTracker.acceptPlainValueDependency(EvaluationTracker.java:146) at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:258) at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateReference(WorkbookEvaluator.java:618) at org.apache.poi.ss.formula.SheetRefEvaluator.getEvalForCell(SheetRefEvaluator.java:47) at org.apache.poi.ss.formula.LazyRefEval.getInnerValueEval(LazyRefEval.java:44) Initial reason is PlainCellCache packing sheet-index to 8 bits, i.e. supporting only 256 sheets. Excel does not limit sheet number ("is limited by available memory"), so 256 is far too low limit. Included patch raises the limit to 4096 (12bit), at the same time dropping the workbook count from 256 to 16 (4bit) which seemed to me more suitable compromise. Documentation should also point out such "invisible limits" and code should Assert the situation when such limits are exceeded, instead of just getting messed up.
A unit test demonstrating the problem, please! Yegor
Created attachment 27234 [details] Test code demonstrating the problem Couldn't find proper documentation on how to write suitable junit for this kind of bug, but simple test-code demonstrating the problem attached.
It is a pretty low-level stuff. Thanks for digging that deep! The patch looks good, but I'm inclined to change the type of the index to long. This way we don't need to compromise between the number of workbooks and worksheets. The fix is coming soon - I'm going to write some tests first. Yegor
Fixed in r1142181, junit added. I changed the type of the index from int to long. This way the number of workbook and sheets is unlimited (actually less 65536). Yegor