[bug-64964] HSSFCell.convertCellValueToBoolean shall throw more specific exception

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884210 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2020-12-08 17:09:36 +00:00
parent 29642eedb1
commit 326ff18e51
3 changed files with 10 additions and 4 deletions

View File

@ -831,6 +831,7 @@ public class HSSFCell extends CellBase {
* setCellValue(boolean) straight afterwards. This method only exists to give
* the cell a somewhat reasonable value until the setCellValue() call (if at all).
* TODO - perhaps a method like setCellTypeAndValue(int, Object) should be introduced to avoid this
* @throws IllegalStateException if cell type cannot be converted to boolean
*/
private boolean convertCellValueToBoolean() {
@ -855,8 +856,9 @@ public class HSSFCell extends CellBase {
case BLANK:
return false;
}
throw new RuntimeException("Unexpected cell type (" + _cellType + ")");
throw new IllegalStateException("Unexpected cell type (" + _cellType + ")");
}
private String convertCellValueToString() {
switch (_cellType) {

View File

@ -915,11 +915,12 @@ public class SXSSFCell extends CellBase {
}
}
}
//COPIED FROM https://svn.apache.org/repos/asf/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java since the functions are declared private there
/**
* Used to help format error messages
*/
private static RuntimeException typeMismatch(CellType expectedTypeCode, CellType actualTypeCode, boolean isFormulaCell) {
private static IllegalStateException typeMismatch(CellType expectedTypeCode, CellType actualTypeCode, boolean isFormulaCell) {
String msg = "Cannot get a " + expectedTypeCode + " value from a " + actualTypeCode
+ " " + (isFormulaCell ? "formula " : "") + "cell";
return new IllegalStateException(msg);
@ -944,7 +945,8 @@ public class SXSSFCell extends CellBase {
case ERROR:
case BLANK:
return false;
default: throw new RuntimeException("Unexpected cell type (" + cellType + ")");
default:
throw new IllegalStateException("Unexpected cell type (" + cellType + ")");
}
}

View File

@ -1143,6 +1143,8 @@ public final class XSSFCell extends CellBase {
* setCellValue(boolean) straight afterwards. This method only exists to give
* the cell a somewhat reasonable value until the setCellValue() call (if at all).
* TODO - perhaps a method like setCellTypeAndValue(CellType, Object) should be introduced to avoid this
*
* @throws IllegalStateException if cell type cannot be converted to boolean
*/
private boolean convertCellValueToBoolean() {
CellType cellType = getCellType();
@ -1168,7 +1170,7 @@ public final class XSSFCell extends CellBase {
return false;
default:
throw new RuntimeException("Unexpected cell type (" + cellType + ")");
throw new IllegalStateException("Unexpected cell type (" + cellType + ")");
}
}