Bug 46479

Summary: [PATCH] evaluateInCell fails if the formula was previously invalid
Product: POI Reporter: Robert Longson <robert_longson>
Component: HSSFAssignee: POI Developers List <dev>
Severity: normal Keywords: PatchAvailable
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: patch

Description Robert Longson 2009-01-05 08:01:08 UTC
Created attachment 23086 [details]

a) Create a formula that is invalid e.g. put XXX in A1 and =A1+1 in B1.
b) Change the value in A1 to 2.5
c) Call HSSFFormulaEvaluator.evaluateInCell on B1

Actual Result: java.lang.IllegalStateException: Cannot get a numeric value from a error formula cell

Expected Result: B1 contains 3.5

POI 3.1 did not have this problem but POI 3.2 and all newer versions including the current trunk do.
Comment 1 Robert Longson 2009-01-05 08:03:59 UTC
Created attachment 23087 [details]
Comment 2 Robert Longson 2009-01-05 08:05:28 UTC
Created attachment 23088 [details]
Comment 3 Josh Micich 2009-01-05 13:12:20 UTC
Thanks for the patch.  There is some ambiguity in original design as to whether setCellType() should be called before or after setCellValue().  The methods overlap in behaviour:  setCellValue() may change the cell type, and setCellType() converts the old cell value to the new type and sets the new value in the cell.
The new ordering of these calls (setCellValue before setCellType) actually causes other junits to fail, but your fix still seems correct to me.

Three other related bugs were found and fixed, and junits added for all of them. 

svn r731715
Comment 4 Josh Micich 2009-12-03 14:23:52 UTC
Additional similar fixes applied in svn r886951

Problems occurred when changing a formula cell to type string.  These cases weren't addressed in the previous fix.