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
This commit is contained in:
Yegor Kozlov 2009-04-20 16:50:05 +00:00
parent db553fd510
commit a5afdd38d2
2 changed files with 9 additions and 3 deletions

View 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;
}

View File

@ -265,6 +265,12 @@ 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);