From 89d734dcb3f9d204c75e3a88fb1013a3f9293307 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 20 Apr 2009 16:50:05 +0000 Subject: [PATCH] avoid NPE when calling XSSF.setCellFormula(null) for a non-formula cell git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@766750 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/xssf/usermodel/XSSFCell.java | 4 ++-- .../org/apache/poi/ss/usermodel/BaseTestCell.java | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 6bbcf1a8c6..3143037430 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -359,9 +359,9 @@ public final class XSSFCell implements Cell { */ public void setCellFormula(String formula) { XSSFWorkbook wb = row.getSheet().getWorkbook(); - if (formula == null && cell.isSetF()) { + if (formula == null) { wb.onDeleteFormula(this); - cell.unsetF(); + if(cell.isSetF()) cell.unsetF(); return; } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 1a987c1ac8..4e747b2898 100755 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -265,7 +265,13 @@ public abstract class BaseTestCell extends TestCase { assertEquals("I changed!", c2.getStringCellValue()); assertEquals(Cell.CELL_TYPE_FORMULA, c2.getCellType()); assertEquals(Cell.CELL_TYPE_STRING, c2.getCachedFormulaResultType()); - } + + //calglin Cell.setCellFormula(null) for a non-formula cell + Cell c3 = r.createCell(2); + c3.setCellFormula(null); + assertEquals(Cell.CELL_TYPE_BLANK, c3.getCellType()); + + } private Cell createACell() { return _testDataProvider.createWorkbook().createSheet("Sheet1").createRow(0).createCell(0); } -- 2.39.5