https://bz.apache.org/bugzilla/show_bug.cgi?id=63057
Bug ID: 63057
Summary: *Cell.setCellValue(String/RichTextString) is not
exception-safe
Product: POI
Version: 4.0.x-dev
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: SS Common
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
In all three implementations of Cell, in setCellValue(String) and
setCellValue(RichTextString) cell is convertyed to STRING before all checks
have passed (or failed). That is, if the passed string exceeds the maximum
length defined by the spreadsheet version, the method wil throw but the cell
contents will have changed.
The fix is simple: perform all checks before any invasive operation.
testcase:
@Test
public void setStringCellValue_ifThrows_shallNotChangeCell() {
Cell cell =
_testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0);
final double value = 2.78;
cell.setCellValue(value);
assertEquals(CellType.NUMERIC, cell.getCellType());
int badLength =
cell.getSheet().getWorkbook().getSpreadsheetVersion().getMaxTextLength() + 1;
String badStringValue = new String(new byte[badLength]);
try {
cell.setCellValue(badStringValue);
} catch (IllegalArgumentException e) {
// no-op, expected to throw but we need to assert something more
}
assertEquals(CellType.NUMERIC, cell.getCellType()); // <- fails
assertEquals(value, cell.getNumericCellValue(), 0); // <- fails, obviously
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]