From 5ec079072a101f21bbf6af72c7755f5f59413969 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 2 Jan 2020 14:58:30 +0000 Subject: [PATCH] [bug-64044] setCellValue(LocalDate) does not support nulls properly git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872246 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/usermodel/Cell.java | 2 +- .../org/apache/poi/ss/usermodel/BaseTestCell.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/poi/ss/usermodel/Cell.java b/src/java/org/apache/poi/ss/usermodel/Cell.java index 5f8f2fe418..ad26ed0882 100644 --- a/src/java/org/apache/poi/ss/usermodel/Cell.java +++ b/src/java/org/apache/poi/ss/usermodel/Cell.java @@ -210,7 +210,7 @@ public interface Cell { * will change the cell to a numerics cell and set its value. */ default void setCellValue(LocalDate value) { - setCellValue(value.atStartOfDay()); + setCellValue(value == null ? null : value.atStartOfDay()); } /** diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 89c4796de7..204ec9504a 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -133,6 +133,21 @@ public abstract class BaseTestCell { assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, CellType.FORMULA, CellType.ERROR); + String strNull = null; + cell.setCellValue(strNull); + assertNull(cell.getRichStringCellValue()); + assertEquals(CellType.BLANK, cell.getCellType()); + + LocalDate ldNull = null; + cell.setCellValue(ldNull); + assertNull(cell.getLocalDateTimeCellValue()); + assertEquals(CellType.BLANK, cell.getCellType()); + + LocalDateTime ldtNull = null; + cell.setCellValue(ldtNull); + assertNull(cell.getLocalDateTimeCellValue()); + assertEquals(CellType.BLANK, cell.getCellType()); + cell.setCellErrorValue(FormulaError.NA.getCode()); assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue()); assertEquals(CellType.ERROR, cell.getCellType()); -- 2.39.5