mirror of https://github.com/apache/poi.git
Fix #57034 on SXSSF, and add a common unit test to show it was already fixed on the others + is now fixed for SXSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1729849 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f597a1717c
commit
6f46cd95be
|
@ -245,7 +245,7 @@ public class SXSSFCell implements Cell {
|
|||
{
|
||||
XSSFRichTextString xvalue = (XSSFRichTextString)value;
|
||||
|
||||
if (xvalue != null) {
|
||||
if (xvalue != null && xvalue.getString() != null) {
|
||||
ensureRichTextStringType();
|
||||
|
||||
if (xvalue.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()) {
|
||||
|
@ -271,16 +271,20 @@ public class SXSSFCell implements Cell {
|
|||
@Override
|
||||
public void setCellValue(String value)
|
||||
{
|
||||
ensureTypeOrFormulaType(CELL_TYPE_STRING);
|
||||
if (value != null) {
|
||||
ensureTypeOrFormulaType(CELL_TYPE_STRING);
|
||||
|
||||
if(value != null && value.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()){
|
||||
throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
|
||||
if(value != null && value.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()){
|
||||
throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
|
||||
}
|
||||
|
||||
if(_value.getType()==CELL_TYPE_FORMULA)
|
||||
((StringFormulaValue)_value).setPreEvaluatedValue(value);
|
||||
else
|
||||
((PlainStringValue)_value).setValue(value);
|
||||
} else {
|
||||
setCellType(CELL_TYPE_BLANK);
|
||||
}
|
||||
|
||||
if(_value.getType()==CELL_TYPE_FORMULA)
|
||||
((StringFormulaValue)_value).setPreEvaluatedValue(value);
|
||||
else
|
||||
((PlainStringValue)_value).setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1380,4 +1380,27 @@ public abstract class BaseTestBugzillaIssues {
|
|||
|
||||
wb.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* If someone sets a null string as a cell value, treat
|
||||
* it as an empty cell, and avoid a NPE on auto-sizing
|
||||
*/
|
||||
@Test
|
||||
public void test57034() throws Exception {
|
||||
Workbook wb = _testDataProvider.createWorkbook();
|
||||
Sheet s = wb.createSheet();
|
||||
Cell cell = s.createRow(0).createCell(0);
|
||||
cell.setCellValue((String)null);
|
||||
assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType());
|
||||
|
||||
_testDataProvider.trackColumnsForAutosizing(s, 0);
|
||||
|
||||
s.autoSizeColumn(0);
|
||||
assertEquals(2048, s.getColumnWidth(0));
|
||||
|
||||
s.autoSizeColumn(0, true);
|
||||
assertEquals(2048, s.getColumnWidth(0));
|
||||
|
||||
wb.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue