Bug 52527 - Failed to find a matching shared formula record
Summary: Failed to find a matching shared formula record
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2012-01-25 18:04 UTC by David Roe
Modified: 2012-03-06 04:01 UTC (History)
1 user (show)

Minimal test case (32.50 KB, application/vnd.ms-excel)
2012-01-25 18:04 UTC, David Roe
Move exception from findFormulaGroupForCell to linkSharedFormulaRecord (1.01 KB, patch)
2012-01-30 10:35 UTC, David Roe
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Roe 2012-01-25 18:04:55 UTC
Created attachment 28209 [details]
Minimal test case

I'm running into an error "Failed to find a matching shared formula record" when saving a spreadsheet. I've whittled it down to a minimal test case which I've attached. Simply loading and saving this file causes the error. I had to remove some sensitive stuff so there are a few formula errors but the file is still valid.

I had a look at the code in org.apache.poi.hssf.record.aggregates.SharedValueManager.findFormulaGroupForCell where the exception is thrown. It mentions 15228.xls which I tried loading and saving and it worked fine.
Comment 1 David Roe 2012-01-30 10:35:15 UTC
Created attachment 28227 [details]
Move exception from findFormulaGroupForCell to linkSharedFormulaRecord
Comment 2 David Roe 2012-01-30 10:35:29 UTC
I've had another look at the source code and findFormulaGroupForCell is called from two places: linkSharedFormulaRecord and getRecordForFirstCell. linkSharedFormulaRecord seems to deal only with shared formulas and so I think the exception is correct in that case. However, getRecordForFirstCell deals with tables and arrays and it makes sense there for findFormulaGroupForCell to return null instead of throwing an exception. The code in getRecordForFirstCell even checks for null (which won't be possible with the current exception-throwing code).

It seems with the current code, a spreadsheet with a shared formula cannot contain any arrays or tables.

I have attached a patch that moves the exception into linkSharedFormulaRecord. I think the TODO comment could also be removed as that file seems to work fine (as mentioned in my earlier comment).
Comment 3 Yegor Kozlov 2012-02-07 10:47:41 UTC
Thanks for the patch. Applied in r1241419, unit test added.