Browse Source

[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
tags/REL_4_1_2
PJ Fanning 4 years ago
parent
commit
5ec079072a

+ 1
- 1
src/java/org/apache/poi/ss/usermodel/Cell.java View 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());
}

/**

+ 15
- 0
src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java View 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());

Loading…
Cancel
Save