From 9fb2c4b03e74a8eee1588321028d3aa0d4264948 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 19 Nov 2025 13:58:18 +0100 Subject: [PATCH] make getCachedResultType return enum (#939) --- .../poi/hssf/extractor/OldExcelExtractor.java | 4 ++-- .../apache/poi/hssf/record/FormulaRecord.java | 19 ++++++++---------- .../poi/hssf/record/OldFormulaRecord.java | 20 ++++++++++--------- .../apache/poi/hssf/usermodel/HSSFCell.java | 6 +++--- .../poi/hssf/record/TestFormulaRecord.java | 3 +-- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java b/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java index 1db03f80bc..1524d4a8d5 100644 --- a/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java +++ b/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java @@ -286,12 +286,12 @@ public class OldExcelExtractor implements POITextExtractor { // Biff 2 and 5+ share the same SID, due to a bug... if (biffVersion == 5) { FormulaRecord fr = new FormulaRecord(ris); - if (fr.getCachedResultTypeEnum() == CellType.NUMERIC) { + if (fr.getCachedResultType() == CellType.NUMERIC) { handleNumericCell(text, fr.getValue()); } } else { OldFormulaRecord fr = new OldFormulaRecord(ris); - if (fr.getCachedResultTypeEnum() == CellType.NUMERIC) { + if (fr.getCachedResultType() == CellType.NUMERIC) { handleNumericCell(text, fr.getValue()); } } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/FormulaRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/FormulaRecord.java index efb65e9f93..4d0c28f894 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/FormulaRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/FormulaRecord.java @@ -123,28 +123,25 @@ public final class FormulaRecord extends CellRecord { /** * @return The type of the cached value or CellType.NUMERIC.getCode() if the cached value is empty * - * @deprecated POI 5.0.0, will be removed in 6.0, use getCachedResultTypeEnum until switch to enum is fully done + * @since POI 6.0.0 */ - @Deprecated - @Removal(version = "6.0.0") - public int getCachedResultType() { + public CellType getCachedResultType() { if (specialCachedValue == null) { - return CellType.NUMERIC.getCode(); + return CellType.NUMERIC; } - return specialCachedValue.getValueType(); + return specialCachedValue.getValueTypeEnum(); } /** * Returns the type of the cached result * * @return The type of the cached value or CellType.NUMERIC if the cached value is empty - * @since POI 5.0.0 + * @deprecated POI 6.0.0, use {@link #getCachedResultType()} instead */ + @Deprecated + @Removal(version="7.0.0") public CellType getCachedResultTypeEnum() { - if (specialCachedValue == null) { - return CellType.NUMERIC; - } - return specialCachedValue.getValueTypeEnum(); + return getCachedResultType(); } public boolean getCachedBooleanValue() { diff --git a/poi/src/main/java/org/apache/poi/hssf/record/OldFormulaRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/OldFormulaRecord.java index dd18abebf6..f6478d752c 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/OldFormulaRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/OldFormulaRecord.java @@ -24,6 +24,7 @@ import org.apache.poi.ss.formula.Formula; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.util.GenericRecordUtil; +import org.apache.poi.util.Removal; /** * Formula Record (0x0006 / 0x0206 / 0x0406) - holds a formula in @@ -65,26 +66,27 @@ public final class OldFormulaRecord extends OldCellRecord { } /** - * @deprecated POI 5.0.0, will be removed in 5.0, use getCachedResultTypeEnum until switch to enum is fully done + * Returns the type of the cached result + * @return A CellType + * @since POI 6.0.0 */ - @Deprecated - public int getCachedResultType() { + public CellType getCachedResultType() { if (specialCachedValue == null) { - return CellType.NUMERIC.getCode(); + return CellType.NUMERIC; } - return specialCachedValue.getValueType(); + return specialCachedValue.getValueTypeEnum(); } /** * Returns the type of the cached result * @return A CellType * @since POI 5.0.0 + * @deprecated POI 6.0.0, use {@link #getCachedResultType()} instead */ + @Deprecated + @Removal(version="7.0.0") public CellType getCachedResultTypeEnum() { - if (specialCachedValue == null) { - return CellType.NUMERIC; - } - return specialCachedValue.getValueTypeEnum(); + return getCachedResultType(); } public boolean getCachedBooleanValue() { diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java index fd4f97365d..ddb3914f26 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -649,7 +649,7 @@ public class HSSFCell extends CellBase { } private static void checkFormulaCachedValueType(CellType expectedTypeCode, FormulaRecord fr) { - CellType cachedValueType = fr.getCachedResultTypeEnum(); + CellType cachedValueType = fr.getCachedResultType(); if (cachedValueType != expectedTypeCode) { throw typeMismatch(expectedTypeCode, cachedValueType, true); } @@ -885,7 +885,7 @@ public class HSSFCell extends CellBase { } FormulaRecordAggregate fra = ((FormulaRecordAggregate)_record); FormulaRecord fr = fra.getFormulaRecord(); - switch (fr.getCachedResultTypeEnum()) { + switch (fr.getCachedResultType()) { case BOOLEAN: return fr.getCachedBooleanValue() ? "TRUE" : "FALSE"; case STRING: @@ -1188,7 +1188,7 @@ public class HSSFCell extends CellBase { throw new IllegalStateException("Only formula cells have cached results"); } - return ((FormulaRecordAggregate)_record).getFormulaRecord().getCachedResultTypeEnum(); + return ((FormulaRecordAggregate)_record).getFormulaRecord().getCachedResultType(); } void setCellArrayFormula(CellRangeAddress range) { diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestFormulaRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestFormulaRecord.java index d9a01a1c61..f1deb0a40f 100644 --- a/poi/src/test/java/org/apache/poi/hssf/record/TestFormulaRecord.java +++ b/poi/src/test/java/org/apache/poi/hssf/record/TestFormulaRecord.java @@ -87,8 +87,7 @@ final class TestFormulaRecord { assertEquals(0, record.getRow(), "Row"); assertEquals(0, record.getColumn(), "Column"); //noinspection deprecation - assertEquals(CellType.ERROR.getCode(), record.getCachedResultType()); - assertEquals(CellType.ERROR, record.getCachedResultTypeEnum()); + assertEquals(CellType.ERROR, record.getCachedResultType()); byte[] output = record.serialize(); // includes sid+recordlength