Bug 58558

Summary: NPE in SXSSFCell.setCellValue(RichTextString) when passing 'null' as parameter
Product: POI Reporter: barney2k7
Component: SXSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.13-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description barney2k7 2015-10-27 10:40:30 UTC
If SXSSFCell.setCellValue(RichTextString) is called with 'null' as parameter, an NPE is thrown:

java.lang.NullPointerException
    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
   */
  @Test
  public void testSetCellValueNullRichTextString() throws IOException {
    Workbook wb = _testDataProvider.createWorkbook();
    Sheet sheet = wb.createSheet();
    Cell cell = sheet.createRow(0).createCell(0);

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

    wb.close();
  }


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.