]> source.dussan.org Git - poi.git/commitdiff
avoid NPE when calling XSSF.setCellFormula(null) for a non-formula cell
authorYegor Kozlov <yegor@apache.org>
Mon, 20 Apr 2009 16:50:05 +0000 (16:50 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 20 Apr 2009 16:50:05 +0000 (16:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@766750 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

index 6bbcf1a8c632f372c4f5f39c0066858d6350a660..3143037430a79f74312a2e9d03c66e16cf4d6335 100644 (file)
@@ -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;
         }
 
index 1a987c1ac81004b57106d911eaadd50de4b4f7a3..4e747b289890d19ae735a97c7f837c2c84f3c84e 100755 (executable)
@@ -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);
        }