Bug 49872 - XSSFFormulaEvaluator.evaluateInCell() with "shared" formula's
Summary: XSSFFormulaEvaluator.evaluateInCell() with "shared" formula's
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.6-dev
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-03 02:25 UTC by alex
Modified: 2010-09-12 05:15 UTC (History)
0 users



Attachments
Example file and code (7.32 KB, application/x-sdlc)
2010-09-06 03:03 UTC, alex
Details

Note You need to log in before you can comment on or make changes to this bug.
Description alex 2010-09-03 02:25:10 UTC
If you have a shared formula, and you run evaluateInCell() on the original formula, the referenced formula's will fail because the original formula can no longer be found, XSSFCell throws a nullpointer exception on "convertSharedFormula()" because "sfCell.getCTCell().getF()" is null.

I'm not entirely sure if this is a bug or a feature.
Comment 1 Yegor Kozlov 2010-09-04 11:27:48 UTC
I'm not quite sure how to reproduce it. Can you attach a sample file and Java code that demonstrates the problem? 


Yegor
Comment 2 alex 2010-09-06 03:03:50 UTC
Created attachment 25990 [details]
Example file and code
Comment 3 Yegor Kozlov 2010-09-12 05:15:31 UTC
It was a bug. The same workbook saved as .xls evaluates OK in HSSF.  

When a group of cells shares a formula then only the first cell in the group contains the actual formula expression. This is considered the 'master' formula cell. Subsequent cells refer to the master by id and adjust the expression based on the cell's relative location to the master formula.

FormulaEvaluator.evaluateInCell changes cell type. This method evaluates the formula, and puts the result back into the cell, in place of the old formula. 
In your case, the first call of evaluateInCell changed the master shared formula and subsequent calls on dependent cells resulted in NPE. 

I committed the fix in r996265. Now you can call evaluateInCell on a group of shared formulas cells in any order - first master then dependent or first dependent cells and then master. 

Yegor