You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2019/01/04 09:48:00 UTC
[Bug 63057] New: *Cell.setCellValue(String/RichTextString) is not
exception-safe
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: dev@poi.apache.org
Reporter: gallon.fizik@gmail.com
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 63057] *Cell.setCellValue(String/RichTextString) is not
exception-safe
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63057
gallon.fizik@gmail.com <ga...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--- Comment #1 from gallon.fizik@gmail.com <ga...@gmail.com> ---
My bad, this only applies to SXSSFCell.
Also this in setCellValue(String):
if(_value.getType()==CellType.FORMULA)
if(_value instanceof NumericFormulaValue) {
((NumericFormulaValue)
_value).setPreEvaluatedValue(Double.parseDouble(value));
}
...
}
never happens because it is preceded by resetting the internal value to a
[Formula]StringValue, so I removed it.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 63057] *Cell.setCellValue(String/RichTextString) is not
exception-safe
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63057
gallon.fizik@gmail.com <ga...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #2 from gallon.fizik@gmail.com <ga...@gmail.com> ---
Fixed in r1850342
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org