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 2020/12/08 06:52:17 UTC
[Bug 64964] New: HSSFCell.convertCellValueToBoolean shall throw more
specific exception
https://bz.apache.org/bugzilla/show_bug.cgi?id=64964
Bug ID: 64964
Summary: HSSFCell.convertCellValueToBoolean shall throw more
specific exception
Product: POI
Version: unspecified
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: HSSF
Assignee: dev@poi.apache.org
Reporter: zhonghao@pku.org.cn
Target Milestone: ---
Given an unknown cell type, this method throws RuntimeException:
private boolean convertCellValueToBoolean() {
switch (_cellType) {
case BOOLEAN:
return (( BoolErrRecord ) _record).getBooleanValue();
case STRING:
int sstIndex = ((LabelSSTRecord)_record).getSSTIndex();
String text =
_book.getWorkbook().getSSTString(sstIndex).getString();
return Boolean.parseBoolean(text);
case NUMERIC:
return ((NumberRecord)_record).getValue() != 0;
case FORMULA:
// use cached formula result if it's the right type:
FormulaRecord fr =
((FormulaRecordAggregate)_record).getFormulaRecord();
checkFormulaCachedValueType(CellType.BOOLEAN, fr);
return fr.getCachedBooleanValue();
// Other cases convert to false
// These choices are not well justified.
case ERROR:
case BLANK:
return false;
}
throw new RuntimeException("Unexpected cell type (" + _cellType + ")");
}
It shall throw more specific exceptions. For example,
ExcelComparator.compareDataInCell throws IllegalStateException:
private void compareDataInCell(Locator loc1, Locator loc2) {
if (isCellTypeMatches(loc1, loc2)) {
final CellType loc1cellType = loc1.cell.getCellType();
switch(loc1cellType) {
case BLANK:
case STRING:
case ERROR:
isCellContentMatches(loc1,loc2);
break;
case BOOLEAN:
isCellContentMatchesForBoolean(loc1,loc2);
break;
case FORMULA:
isCellContentMatchesForFormula(loc1,loc2);
break;
case NUMERIC:
if (DateUtil.isCellDateFormatted(loc1.cell)) {
isCellContentMatchesForDate(loc1,loc2);
} else {
isCellContentMatchesForNumeric(loc1,loc2);
}
break;
default:
throw new IllegalStateException("Unexpected cell type: " +
loc1cellType);
}
}
...
}
The latter is more reasonable, and easy to be caught.
--
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 64964] HSSFCell.convertCellValueToBoolean shall throw more
specific exception
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64964
--- Comment #2 from PJ Fanning <fa...@yahoo.com> ---
And r1884210
--
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 64964] HSSFCell.convertCellValueToBoolean shall throw more
specific exception
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64964
PJ Fanning <fa...@yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #1 from PJ Fanning <fa...@yahoo.com> ---
Merged r1884211
--
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