Bug 58558 - NPE in SXSSFCell.setCellValue(RichTextString) when passing 'null' as parameter
Summary: NPE in SXSSFCell.setCellValue(RichTextString) when passing 'null' as parameter
Alias: None
Product: POI
Classification: Unclassified
Component: SXSSF (show other bugs)
Version: 3.13-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2015-10-27 10:40 UTC by barney2k7
Modified: 2015-10-28 17:43 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description barney2k7 2015-10-27 10:40:30 UTC
If SXSSFCell.setCellValue(RichTextString) is called with 'null' as parameter, an NPE is thrown:

    at org.apache.poi.xssf.usermodel.XSSFRichTextString.length(XSSFRichTextString.java:328)
    at org.apache.poi.xssf.streaming.SXSSFCell.setCellValue(SXSSFCell.java:232)
    at ...

This seems to be a bug, as the javadoc of that method clearly states "If value is null then we will change the cell to a Blank cell."

Other Cell implementations (e.g. XSSFCell) correctly implement what javadoc promises.
Comment 1 Dominik Stadler 2015-10-27 16:09:58 UTC
This is fixed in POI 3.13 via Bug 58113 already, please update and try again.
Comment 2 barney2k7 2015-10-28 12:04:11 UTC
This is not a duplicate of Bug 58113: 

SXSSFCell.setCellValue(RichTextString) is still broken in 3.13

Bug 58113 only fixed SXSSFCell.setCellValue(String)

PS: 3.13-FINAL isn't available in the Version Field of Bugzilla, you might want to add that
Comment 3 Nick Burch 2015-10-28 12:49:51 UTC
Any chance you could write a short junit unit test that shows the problem still occurring? We can then use that to verify the fix, when done, and also to ensure that it doesn't get broken in the future

Also, missing versions added to bugzilla, thanks for reminding us!
Comment 4 barney2k7 2015-10-28 15:07:53 UTC
Here's a test case that you can add to org.apache.poi.ss.usermodel.BaseTestCell:

   * Test case for 58558
  public void testSetCellValueNullRichTextString() throws IOException {
    Workbook wb = _testDataProvider.createWorkbook();
    Sheet sheet = wb.createSheet();
    Cell cell = sheet.createRow(0).createCell(0);

    RichTextString str = null;
    assertEquals("", cell.getStringCellValue());


It fails with NPE for SXSSF, but works fine for XSSF and HSSF (all using poi 3.13 final release)
Comment 5 Nick Burch 2015-10-28 17:43:11 UTC
Thanks for that. Fuller test case and a SXSSF fix added in r1711082.