Browse Source

[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
tags/before_ooxml_3rd_edition
PJ Fanning 3 years ago
parent
commit
326ff18e51

+ 3
- 1
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java 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) {

+ 4
- 2
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java 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 + ")");
}

}

+ 3
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java 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 + ")");
}
}


Loading…
Cancel
Save