Author: centic
Date: Mon Jul 13 12:17:52 2015
New Revision: 1690652
URL: http://svn.apache.org/r1690652
Log:
Bug 58113: Fix regression: NullPointerException when setting cell value to null
add unit tests which verifies this for all three SS-implementations
Modified:
poi/site/src/documentation/content/xdocs/status.xml
poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
Modified: poi/site/src/documentation/content/xdocs/status.xml
URL:
http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1690652&r1=1690651&r2=1690652&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Mon Jul 13 12:17:52 2015
@@ -38,7 +38,8 @@
<person id="YK" name="Yegor Kozlov" email="[email protected]" />
</devs>
- <release version="3.13-beta1" date="2015-??-??">
+ <release version="3.13-beta1" date="2015-07-??">
+ <action dev="PD" type="fix" fixes-bug="58113">Regression:
NullPointerException when setting cell value to null</action>
<action dev="DN" type="add" fixes-bug="58036">Add basic support for
VBA macro-enabled workbooks (xlsm)</action>
<action dev="PD" type="fix" fixes-bug="57744">Fix parsing the email
submission data when id contains a hyphen</action>
<action dev="PD" type="fix" fixes-bug="57678">Better handle years in
mail-messages between 1980 and 1999</action>
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java?rev=1690652&r1=1690651&r2=1690652&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java Mon
Jul 13 12:17:52 2015
@@ -248,7 +248,7 @@ public class SXSSFCell implements Cell
{
ensureTypeOrFormulaType(CELL_TYPE_STRING);
- if(value.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()){
+ if(value != null && value.length() >
SpreadsheetVersion.EXCEL2007.getMaxTextLength()){
throw new IllegalArgumentException("The maximum length of cell
contents (text) is 32,767 characters");
}
Modified:
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java?rev=1690652&r1=1690651&r2=1690652&view=diff
==============================================================================
---
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
(original)
+++
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
Mon Jul 13 12:17:52 2015
@@ -32,6 +32,7 @@ import org.apache.poi.hssf.util.PaneInfo
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -419,16 +420,16 @@ public abstract class BaseTestBugzillaIs
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("My sheet");
- Row row = sheet.createRow( 0 );
- Cell cell = row.createCell( 0 );
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
cell.setCellFormula(hyperlinkF);
assertEquals(hyperlinkF, cell.getCellFormula());
wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheet("My Sheet");
- row = sheet.getRow( 0 );
- cell = row.getCell( 0 );
+ row = sheet.getRow(0);
+ cell = row.getCell(0);
assertEquals(hyperlinkF, cell.getCellFormula());
}
@@ -691,7 +692,8 @@ public abstract class BaseTestBugzillaIs
* TODO Fix this to evaluate for XSSF
* TODO Fix this to work at all for HSSF
*/
-// @Test
+ @Ignore("Fix this to evaluate for XSSF, Fix this to work at all for HSSF")
+ @Test
public void bug46670() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet();
@@ -730,7 +732,7 @@ public abstract class BaseTestBugzillaIs
assertEquals(refHttp, c2.getCellFormula());
- // Try to evalutate, without giving a way to get at the other file
+ // Try to evaluate, without giving a way to get at the other file
try {
evaluateCell(wb, c1);
fail("Shouldn't be able to evaluate without the other file");
@@ -1003,4 +1005,44 @@ public abstract class BaseTestBugzillaIs
fail();
} catch(IllegalStateException e) {}
}
+
+ @Test
+ public void test58113() {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sheet = wb.createSheet( "Test" );
+
+ Row row = sheet.createRow(0);
+
+ Cell cell = row.createCell(0);
+ // verify that null-values can be set, this was possible up to 3.11,
but broken in 3.12
+ cell.setCellValue((String)null);
+ String value = cell.getStringCellValue();
+ assertTrue("HSSF will currently return empty string, XSSF/SXSSF will
return null, but had: " + value,
+ value == null || value.length() == 0);
+
+ cell = row.createCell(1);
+ // also verify that setting formulas to null works
+ cell.setCellType(Cell.CELL_TYPE_FORMULA);
+ cell.setCellValue((String)null);
+
+ wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
+
+ value = cell.getStringCellValue();
+ assertTrue("HSSF will currently return empty string, XSSF/SXSSF will
return null, but had: " + value,
+ value == null || value.length() == 0);
+
+ // set some value
+ cell.setCellType(Cell.CELL_TYPE_STRING);
+ cell.setCellValue("somevalue");
+
+ value = cell.getStringCellValue();
+ assertTrue("can set value afterwards: " + value,
+ value.equals("somevalue"));
+
+ // verify that the null-value is actually set even if there was some
value in the cell before
+ cell.setCellValue((String)null);
+ value = cell.getStringCellValue();
+ assertTrue("HSSF will currently return empty string, XSSF/SXSSF will
return null, but had: " + value,
+ value == null || value.length() == 0);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]