From: PJ Fanning Date: Tue, 8 Dec 2020 17:09:36 +0000 (+0000) Subject: [bug-64964] HSSFCell.convertCellValueToBoolean shall throw more specific exception X-Git-Tag: before_ooxml_3rd_edition~23 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=326ff18e51cccabeef0c4d15d666354399fcd962;p=poi.git [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 --- diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 9c54fbb84f..a29179ad23 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -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) { diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java index 2f9be443e1..4eb67ea8a5 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java @@ -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 + ")"); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index af604234d4..025726e19d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -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 + ")"); } }