]> source.dussan.org Git - poi.git/commitdiff
[bug-64044] setCellValue(LocalDate) does not support nulls properly
authorPJ Fanning <fanningpj@apache.org>
Thu, 2 Jan 2020 14:58:30 +0000 (14:58 +0000)
committerPJ Fanning <fanningpj@apache.org>
Thu, 2 Jan 2020 14:58:30 +0000 (14:58 +0000)
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
src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

index 5f8f2fe4184b1adf73304c86cd2fc46027bc767d..ad26ed0882fb83ff5e86f8b42bdf86fe69f3bfe8 100644 (file)
@@ -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());
     }
 
     /**
index 89c4796de716cdd55c3e76bd49357d7dbb7a2519..204ec9504a735f648dc36e13080ea0d31c90b6bf 100644 (file)
@@ -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());