Bug 46479 - [PATCH] evaluateInCell fails if the formula was previously invalid
Summary: [PATCH] evaluateInCell fails if the formula was previously invalid
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2009-01-05 08:01 UTC by Robert Longson
Modified: 2009-12-03 14:23 UTC (History)
0 users



Attachments
patch (522 bytes, patch)
2009-01-05 08:01 UTC, Robert Longson
Details | Diff
testcase (2.46 KB, text/plain)
2009-01-05 08:03 UTC, Robert Longson
Details
testcase (13.50 KB, application/octet-stream)
2009-01-05 08:05 UTC, Robert Longson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Longson 2009-01-05 08:01:08 UTC
Created attachment 23086 [details]
patch

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]
testcase
Comment 2 Robert Longson 2009-01-05 08:05:28 UTC
Created attachment 23088 [details]
testcase
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.