Bug 52527

Summary: Failed to find a matching shared formula record
Product: POI Reporter: David Roe <d.roe>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: zjuwufan
Priority: P2    
Version: 3.8-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Minimal test case
Move exception from findFormulaGroupForCell to linkSharedFormulaRecord

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.

Yegor