Bug 47493 - HSSFCell.setCellValue(String value) & HSSFRichTextString
Summary: HSSFCell.setCellValue(String value) & HSSFRichTextString
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.2-FINAL
Hardware: All All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-07 19:31 UTC by apache
Modified: 2009-07-07 23:12 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description apache 2009-07-07 19:31:31 UTC
The now deprecated method HSSFCell.setCellValue(String value)
has been changed to call the new method setCellValue(HSSFRichTextString value)
with a HSSFRichTextString Object.

The problem with that, is that a null String gets replaced with
a HSSFRichTextString Object with the value "" (i.e. length 0).

This broke our application, which I have fixed by calling
setCellValue((HSSFRichTextString)null)

I believe the correct implementation of HSSFCell.setCellValue(String value) should be:
if (value == null) {
setCellValue((HSSFRichTextString)null);
} else {
setCellValue(new HSSFRichTextString(value));
}

This would be much more likely to be backward compatible with existing code.
I'm sure others will be having this problem, but have maybe not yet noticed
the subtle difference in their reports.

Best regards,
DaveLaw
Comment 1 Yegor Kozlov 2009-07-07 23:12:23 UTC
Please try POI-3.5-beta7 or the latest trunk, the fix is already there:

    public void setCellValue(String value) {
        HSSFRichTextString str = value == null ? null :  new HSSFRichTextString(value);
        setCellValue(str);
    }

Yegor