Bug 59199

Summary: setting null value to date cell leads to NPE
Product: POI Reporter: jupp.strunk
Component: XSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.14-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description jupp.strunk 2016-03-18 14:08:24 UTC
When setting a Date value in a cell and the date is null, a NullPointerException is thrown.


  private void createRow(Sheet sheet, Person person) {
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);

If person.getBirthdate() is null we get a NPE:

	at java.util.Calendar.setTime(Calendar.java:1770)
	at org.apache.poi.ss.usermodel.DateUtil.getExcelDate(DateUtil.java:76)
	at org.apache.poi.xssf.usermodel.XSSFCell.setCellValue(XSSFCell.java:742)

My workaround is to check for null and in this case set 
       cell.setCellValue((String) null);

However, in my opinion Cell.setCellValue(Date value) should take care of this, just like Cell.setCellValue(String value)
Comment 1 Dominik Stadler 2016-03-28 20:26:01 UTC
This has been adjusted via r1736923, passing null to setValue() for Date and Calendar leads to a CELL_TYPE_BLANK similar to how String and RichtTextString are handled already.