From 59b16f025bf98cd411482243aa3601bdb8dbc722 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 14 Sep 2022 01:12:38 +0000 Subject: [PATCH] try to use IllegalStateException instead of RuntimeException git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1904050 13f79535-47bb-0310-9956-ffa450edef68 --- .../hemf/record/emfplus/HemfPlusImage.java | 9 +- .../poi/hemf/record/emfplus/HemfPlusPen.java | 4 +- .../common/usermodel/fonts/FontHeader.java | 4 +- .../poi/ddf/EscherChildAnchorRecord.java | 2 +- .../apache/poi/ddf/EscherMetafileBlip.java | 2 +- .../org/apache/poi/hpsf/VariantSupport.java | 2 +- .../extractor/EventBasedExcelExtractor.java | 2 +- .../poi/hssf/extractor/ExcelExtractor.java | 2 +- .../poi/hssf/model/InternalWorkbook.java | 6 +- .../org/apache/poi/hssf/model/LinkTable.java | 14 +- .../record/EmbeddedObjectRefSubRecord.java | 2 +- .../poi/hssf/record/EscherAggregate.java | 2 +- .../poi/hssf/record/SharedFormulaRecord.java | 2 +- .../org/apache/poi/hssf/record/SubRecord.java | 2 +- .../ColumnInfoRecordsAggregate.java | 4 +- .../aggregates/ValueRecordsAggregate.java | 6 +- .../record/crypto/Biff8DecryptingStream.java | 2 +- .../poi/hssf/usermodel/DVConstraint.java | 6 +- .../poi/hssf/usermodel/FontDetails.java | 2 +- .../apache/poi/hssf/usermodel/HSSFCell.java | 2 +- .../hssf/usermodel/HSSFFormulaEvaluator.java | 2 +- .../poi/hssf/usermodel/HSSFPalette.java | 2 +- .../apache/poi/hssf/usermodel/HSSFRow.java | 4 +- .../apache/poi/hssf/usermodel/HSSFSheet.java | 2 +- .../poi/hssf/usermodel/HSSFWorkbook.java | 2 +- .../poi/hssf/usermodel/StaticFontMetrics.java | 2 +- .../poifs/crypt/ChunkedCipherInputStream.java | 2 +- .../poi/poifs/filesystem/DirectoryNode.java | 2 +- .../poi/poifs/filesystem/EntryUtils.java | 2 +- .../poi/poifs/filesystem/POIFSFileSystem.java | 2 +- .../poi/poifs/filesystem/POIFSStream.java | 6 +- .../filesystem/TempFilePOIFSFileSystem.java | 2 +- .../org/apache/poi/sl/draw/SLGraphics.java | 2 +- .../poi/sl/draw/geom/PresetGeometries.java | 2 +- .../apache/poi/ss/format/SimpleFraction.java | 4 +- .../CollaboratingWorkbooksEnvironment.java | 2 +- .../apache/poi/ss/formula/FormulaParser.java | 244 +++++++++--------- .../poi/ss/formula/FormulaRenderer.java | 2 +- .../ss/formula/OperandClassTransformer.java | 2 +- .../formula/OperationEvaluationContext.java | 14 +- .../ss/formula/OperationEvaluatorFactory.java | 2 +- .../poi/ss/formula/SheetNameFormatter.java | 8 +- .../poi/ss/formula/UserDefinedFunction.java | 15 +- .../poi/ss/formula/WorkbookEvaluator.java | 20 +- .../ss/formula/atp/YearFracCalculator.java | 2 +- .../apache/poi/ss/formula/eval/ErrorEval.java | 2 +- .../poi/ss/formula/eval/OperandResolver.java | 4 +- .../eval/forked/ForkedEvaluationCell.java | 2 +- .../eval/forked/ForkedEvaluationWorkbook.java | 2 +- .../formula/function/FunctionDataBuilder.java | 4 +- .../function/FunctionMetadataReader.java | 12 +- .../formula/functions/ArrayFunctionUtils.java | 2 +- .../poi/ss/formula/functions/Countif.java | 6 +- .../poi/ss/formula/functions/Index.java | 4 +- .../poi/ss/formula/functions/Lookup.java | 4 +- .../poi/ss/formula/functions/LookupUtils.java | 6 +- .../poi/ss/formula/functions/Match.java | 6 +- .../apache/poi/ss/formula/functions/Mode.java | 2 +- .../MultiOperandNumericFunction.java | 2 +- .../poi/ss/formula/functions/Offset.java | 2 +- .../poi/ss/formula/functions/Sumproduct.java | 6 +- .../poi/ss/formula/functions/Trend.java | 2 +- .../ss/formula/ptg/AbstractFunctionPtg.java | 6 +- .../apache/poi/ss/formula/ptg/Area3DPtg.java | 2 +- .../apache/poi/ss/formula/ptg/ArrayPtg.java | 2 +- .../poi/ss/formula/ptg/DeletedArea3DPtg.java | 2 +- .../poi/ss/formula/ptg/DeletedRef3DPtg.java | 2 +- .../org/apache/poi/ss/formula/ptg/ErrPtg.java | 2 +- .../org/apache/poi/ss/formula/ptg/ExpPtg.java | 2 +- .../apache/poi/ss/formula/ptg/FuncPtg.java | 2 +- .../apache/poi/ss/formula/ptg/NamePtg.java | 2 +- .../apache/poi/ss/formula/ptg/NameXPtg.java | 2 +- .../apache/poi/ss/formula/ptg/Ref3DPtg.java | 2 +- .../org/apache/poi/ss/formula/ptg/TblPtg.java | 2 +- .../poi/ss/formula/ptg/ValueOperatorPtg.java | 2 +- .../poi/ss/usermodel/DataFormatter.java | 2 +- .../org/apache/poi/ss/util/AreaReference.java | 4 +- .../poi/ss/util/CellRangeAddressList.java | 4 +- .../org/apache/poi/ss/util/CellRangeUtil.java | 2 +- .../poi/ss/util/NumberToTextConverter.java | 12 +- .../java/org/apache/poi/util/HexRead.java | 2 +- .../java/org/apache/poi/util/IOUtils.java | 2 +- .../LittleEndianByteArrayOutputStream.java | 2 +- .../poi/util/LittleEndianInputStream.java | 14 +- .../poi/util/LittleEndianOutputStream.java | 14 +- .../java/org/apache/poi/util/XMLHelper.java | 2 +- 86 files changed, 299 insertions(+), 285 deletions(-) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java index e764e78a1e..6afb53cdd3 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java @@ -447,6 +447,11 @@ public class HemfPlusImage { return new Rectangle2D.Double(1,1,1,1); } + /** + * @param continuedObjectData list of object data + * @return byte array + * @throws IllegalStateException if the data cannot be read + */ public byte[] getRawData(List continuedObjectData) { try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { bos.write(getImageData()); @@ -457,7 +462,7 @@ public class HemfPlusImage { } return bos.toByteArray(); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -491,7 +496,7 @@ public class HemfPlusImage { private HemfPlusGDIImageRenderer getGDIRenderer() { if (getImageDataType() != EmfPlusImageDataType.BITMAP || getBitmapType() != EmfPlusBitmapDataType.PIXEL) { - throw new RuntimeException("image data is not a GDI image"); + throw new IllegalStateException("image data is not a GDI image"); } HemfPlusGDIImageRenderer renderer = new HemfPlusGDIImageRenderer(); renderer.setWidth(getBitmapWidth()); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java index 42dd6e44e6..2f6085f391 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java @@ -474,7 +474,7 @@ public class HemfPlusPen { // A 32-bit unsigned integer that specifies the number of elements in the DashedLineData field. int dashesSize = leis.readInt(); if (dashesSize < 0 || dashesSize > 1000) { - throw new RuntimeException("Invalid dash data size"); + throw new IllegalStateException("Invalid dash data size"); } // An array of DashedLineDataSize floating-point values that specify the lengths of the dashes and spaces in a dashed line. @@ -499,7 +499,7 @@ public class HemfPlusPen { // A 32-bit unsigned integer that specifies the number of elements in the CompoundLineData field. int compoundSize = leis.readInt(); if (compoundSize < 0 || compoundSize > 1000) { - throw new RuntimeException("Invalid compound line data size"); + throw new IllegalStateException("Invalid compound line data size"); } // An array of CompoundLineDataSize floating-point values that specify the compound line of a pen. diff --git a/poi/src/main/java/org/apache/poi/common/usermodel/fonts/FontHeader.java b/poi/src/main/java/org/apache/poi/common/usermodel/fonts/FontHeader.java index 2589b16f17..5c85980a96 100644 --- a/poi/src/main/java/org/apache/poi/common/usermodel/fonts/FontHeader.java +++ b/poi/src/main/java/org/apache/poi/common/usermodel/fonts/FontHeader.java @@ -149,7 +149,7 @@ public class FontHeader implements FontInfo, GenericRecord { fontDataSize = leis.readInt(); version = leis.readInt(); if (version != 0x00010000 && version != 0x00020001 && version != 0x00020002) { - throw new RuntimeException("not a EOT font data stream"); + throw new IllegalStateException("not a EOT font data stream"); } flags = leis.readInt(); leis.readFully(panose); @@ -159,7 +159,7 @@ public class FontHeader implements FontInfo, GenericRecord { fsType = leis.readUShort(); magic = leis.readUShort(); if (magic != 0x504C) { - throw new RuntimeException("not a EOT font data stream"); + throw new IllegalStateException("not a EOT font data stream"); } unicodeRange1 = leis.readInt(); unicodeRange2 = leis.readInt(); diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherChildAnchorRecord.java b/poi/src/main/java/org/apache/poi/ddf/EscherChildAnchorRecord.java index bf15c83047..f5df8f2e66 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherChildAnchorRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherChildAnchorRecord.java @@ -69,7 +69,7 @@ public class EscherChildAnchorRecord extends EscherRecord { field_4_dy2 = LittleEndian.getShort( data, pos + size );size+=2; break; default: - throw new RuntimeException("Invalid EscherChildAnchorRecord - neither 8 nor 16 bytes."); + throw new IllegalStateException("Invalid EscherChildAnchorRecord - neither 8 nor 16 bytes."); } return 8 + size; diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java index 8feafedcc1..d5dceb43fc 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java @@ -416,7 +416,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord { } raw_pictureData = bos.toByteArray(); } catch (IOException e) { - throw new RuntimeException("Can't compress metafile picture data", e); + throw new IllegalStateException("Can't compress metafile picture data", e); } setCompressedSize(raw_pictureData.length); diff --git a/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java b/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java index 71da6ad2da..f6da239c8b 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java +++ b/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java @@ -177,7 +177,7 @@ public class VariantSupport extends Variant { final byte[] v = IOUtils.toByteArray(lei, length, CodePageString.getMaxRecordLength()); throw new ReadingNotSupportedException( type, v ); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } diff --git a/poi/src/main/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java b/poi/src/main/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java index a3239def70..f9af178a5a 100644 --- a/poi/src/main/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java +++ b/poi/src/main/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java @@ -140,7 +140,7 @@ public class EventBasedExcelExtractor implements POIOLE2TextExtractor, org.apach text = text + "\n"; } } catch(IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } return text; diff --git a/poi/src/main/java/org/apache/poi/hssf/extractor/ExcelExtractor.java b/poi/src/main/java/org/apache/poi/hssf/extractor/ExcelExtractor.java index 9f8664c503..8b684f2d32 100644 --- a/poi/src/main/java/org/apache/poi/hssf/extractor/ExcelExtractor.java +++ b/poi/src/main/java/org/apache/poi/hssf/extractor/ExcelExtractor.java @@ -360,7 +360,7 @@ public class ExcelExtractor implements POIOLE2TextExtractor, org.apache.poi.ss.e } break; default: - throw new RuntimeException("Unexpected cell type (" + cell.getCellType() + ")"); + throw new IllegalStateException("Unexpected cell type (" + cell.getCellType() + ")"); } // Output the comment, if requested and exists diff --git a/poi/src/main/java/org/apache/poi/hssf/model/InternalWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/model/InternalWorkbook.java index 82a3838414..7ca3b143ee 100644 --- a/poi/src/main/java/org/apache/poi/hssf/model/InternalWorkbook.java +++ b/poi/src/main/java/org/apache/poi/hssf/model/InternalWorkbook.java @@ -723,7 +723,7 @@ public final class InternalWorkbook { private void checkSheets(int sheetnum) { if ((boundsheets.size()) <= sheetnum) { // if we're short one add another.. if ((boundsheets.size() + 1) <= sheetnum) { - throw new RuntimeException("Sheet number out of bounds!"); + throw new IllegalStateException("Sheet number out of bounds!"); } BoundSheetRecord bsr = createBoundSheet(sheetnum); @@ -1640,7 +1640,7 @@ public final class InternalWorkbook { NameRecord name = new NameRecord(builtInName, sheetNumber); if(linkTable.nameAlreadyExists(name)) { - throw new RuntimeException("Builtin (" + builtInName + throw new IllegalStateException("Builtin (" + builtInName + ") already exists for sheet (" + sheetNumber + ")"); } addName(name); @@ -1813,7 +1813,7 @@ public final class InternalWorkbook { if (rec instanceof PaletteRecord) { palette = (PaletteRecord) rec; } else { - throw new RuntimeException("InternalError: Expected PaletteRecord but got a '"+rec+"'"); + throw new IllegalStateException("InternalError: Expected PaletteRecord but got a '"+rec+"'"); } } else { palette = createPalette(); diff --git a/poi/src/main/java/org/apache/poi/hssf/model/LinkTable.java b/poi/src/main/java/org/apache/poi/hssf/model/LinkTable.java index 25f4aff843..e0c5b1ad6e 100644 --- a/poi/src/main/java/org/apache/poi/hssf/model/LinkTable.java +++ b/poi/src/main/java/org/apache/poi/hssf/model/LinkTable.java @@ -243,7 +243,7 @@ final class LinkTable { int nItems = temp.size(); if (nItems < 1) { - throw new RuntimeException("Expected an EXTERNSHEET record but got (" + throw new IllegalStateException("Expected an EXTERNSHEET record but got (" + rs.peekNextClass().getName() + ")"); } if (nItems == 1) { @@ -274,7 +274,7 @@ final class LinkTable { if (idx < 0) { idx = findFirstRecordLocBySid(SSTRecord.sid) - 1; if (idx < 0) { - throw new RuntimeException("CountryRecord or SSTRecord not found"); + throw new IllegalStateException("CountryRecord or SSTRecord not found"); } } _workbookRecordList.add(idx + 1, _externSheetRecord); @@ -443,7 +443,7 @@ final class LinkTable { public int getExternalSheetIndex(String workbookName, String firstSheetName, String lastSheetName) { int externalBookIndex = getExternalWorkbookIndex(workbookName); if (externalBookIndex == -1) { - throw new RuntimeException("No external workbook with name '" + workbookName + "'"); + throw new IllegalStateException("No external workbook with name '" + workbookName + "'"); } SupBookRecord ebrTarget = _externalBookBlocks[externalBookIndex].getExternalBookRecord(); @@ -465,7 +465,7 @@ final class LinkTable { } } - throw new RuntimeException("External workbook does not contain sheet '" + sheetName + "'"); + throw new IllegalStateException("External workbook does not contain sheet '" + sheetName + "'"); } /** @@ -508,10 +508,10 @@ final class LinkTable { } } if (thisWbIndex < 0) { - throw new RuntimeException("Could not find 'internal references' EXTERNALBOOK"); + throw new IllegalStateException("Could not find 'internal references' EXTERNALBOOK"); } if (_externSheetRecord == null) { - throw new RuntimeException("Did not have an external sheet record, having blocks: " + + throw new IllegalStateException("Did not have an external sheet record, having blocks: " + _externalBookBlocks.length); } @@ -543,7 +543,7 @@ final class LinkTable { int firstTabIndex = _externSheetRecord.getFirstSheetIndexFromRefIndex(refIndex); if (firstTabIndex == -1) { // The referenced sheet could not be found - throw new RuntimeException("Referenced sheet could not be found"); + throw new IllegalStateException("Referenced sheet could not be found"); } // Does it exist via the external book block? diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java index 07e801175b..ec1dce3ffb 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java @@ -190,7 +190,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { } return null; } catch (IOException e) { - throw new RuntimeException("Unexpected exception in readRefPtg", e); + throw new IllegalStateException("Unexpected exception in readRefPtg", e); } } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java b/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java index 53e836dc00..717b866c85 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java @@ -1040,7 +1040,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { try { buffer.write(data); } catch (IOException e) { - throw new RuntimeException("Couldn't get data from drawing/continue records", e); + throw new IllegalStateException("Couldn't get data from drawing/continue records", e); } } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/SharedFormulaRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/SharedFormulaRecord.java index c6a3b986c5..d901e7d492 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/SharedFormulaRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/SharedFormulaRecord.java @@ -95,7 +95,7 @@ public final class SharedFormulaRecord extends SharedValueRecordBase { int formulaColumn = formula.getColumn(); //Sanity checks if (!isInRange(formulaRow, formulaColumn)) { - throw new RuntimeException("Shared Formula Conversion: Coding Error"); + throw new IllegalStateException("Shared Formula Conversion: Coding Error"); } SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97); diff --git a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java index 246d6cc62e..0c18b2b2ec 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java @@ -139,7 +139,7 @@ public abstract class SubRecord implements Duplicatable, GenericRecord { UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(size); serialize(new LittleEndianOutputStream(baos)); if (baos.size() != size) { - throw new RuntimeException("write size mismatch"); + throw new IllegalStateException("write size mismatch"); } return baos.toByteArray(); } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java b/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java index b6dd6688cd..99a9957574 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java @@ -53,7 +53,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate implements cirPrev = cir; } if (records.size() < 1) { - throw new RuntimeException("No column info records found"); + throw new IllegalStateException("No column info records found"); } if (!isInOrder) { records.sort(ColumnInfoRecordsAggregate::compareColInfos); @@ -97,7 +97,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate implements if (cirPrev != null && compareColInfos(cirPrev, cir) > 0) { // Excel probably wouldn't mind, but there is much logic in this class // that assumes the column info records are kept in order - throw new RuntimeException("Column info records are out of order"); + throw new IllegalStateException("Column info records are out of order"); } cirPrev = cir; } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java b/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java index 185a484969..3407d571c2 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java @@ -101,15 +101,15 @@ public final class ValueRecordsAggregate implements Iterable= records.length) { - throw new RuntimeException("cell row is out of range"); + throw new IllegalStateException("cell row is out of range"); } CellValueRecordInterface[] rowCells = records[row]; if (rowCells == null) { - throw new RuntimeException("cell row is already empty"); + throw new IllegalStateException("cell row is already empty"); } short column = cell.getColumn(); if (column >= rowCells.length) { - throw new RuntimeException("cell column is out of range"); + throw new IllegalStateException("cell column is out of range"); } rowCells[column] = null; } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java b/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java index 74699d1bb1..63ed8e1fad 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java @@ -99,7 +99,7 @@ public final class Biff8DecryptingStream implements BiffHeaderInput, LittleEndia double result = Double.longBitsToDouble(valueLongBits); if (Double.isNaN(result)) { // (Because Excel typically doesn't write NaN - throw new RuntimeException("Did not expect to read NaN"); + throw new IllegalStateException("Did not expect to read NaN"); } return result; } diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/DVConstraint.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/DVConstraint.java index 1c53ba2043..475264a559 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/DVConstraint.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/DVConstraint.java @@ -231,7 +231,7 @@ public class DVConstraint implements DataValidationConstraint { try { return Double.valueOf(numberStr); } catch (NumberFormatException e) { - throw new RuntimeException("The supplied text '" + numberStr + throw new IllegalStateException("The supplied text '" + numberStr + "' could not be parsed as a number"); } } @@ -260,7 +260,7 @@ public class DVConstraint implements DataValidationConstraint { try { dateVal = dateFormat.parse(dateStr); } catch (ParseException e) { - throw new RuntimeException("Failed to parse date '" + dateStr + throw new IllegalStateException("Failed to parse date '" + dateStr + "' using specified format '" + dateFormat + "'", e); } } @@ -323,7 +323,7 @@ public class DVConstraint implements DataValidationConstraint { @Override public void setExplicitListValues(String[] explicitListValues) { if (_validationType != ValidationType.LIST) { - throw new RuntimeException("Cannot setExplicitListValues on non-list constraint"); + throw new IllegalStateException("Cannot setExplicitListValues on non-list constraint"); } _formula1 = null; _explicitListValues = explicitListValues; diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/FontDetails.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/FontDetails.java index d9fc1d54c2..f793c49c79 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/FontDetails.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/FontDetails.java @@ -116,7 +116,7 @@ public class FontDetails String[] charactersStrArray = split(charactersStr, ",", -1); String[] widthsStrArray = split(widthsStr, ",", -1); if (charactersStrArray.length != widthsStrArray.length) - throw new RuntimeException("Number of characters does not number of widths for font " + fontName); + throw new IllegalStateException("Number of characters does not number of widths for font " + fontName); for ( int i = 0; i < widthsStrArray.length; i++ ) { if (charactersStrArray[i].length() != 0) 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 8fec6a00a1..d11372079b 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 @@ -219,7 +219,7 @@ public class HSSFCell extends CellBase { ? CellType.BOOLEAN : CellType.ERROR; } - throw new RuntimeException("Bad cell value rec (" + cval.getClass().getName() + ")"); + throw new IllegalStateException("Bad cell value rec (" + cval.getClass().getName() + ")"); } /** diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index b64a501866..a0aafd7d5c 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -214,7 +214,7 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { if (eval instanceof ErrorEval) { return CellValue.getError(((ErrorEval)eval).getErrorCode()); } - throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")"); + throw new IllegalStateException("Unexpected eval class (" + eval.getClass().getName() + ")"); } @Override diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPalette.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPalette.java index 61ca511c2e..d2fa999d4f 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPalette.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPalette.java @@ -173,7 +173,7 @@ public final class HSSFPalette { return getColor(i); } } - throw new RuntimeException("Could not find free color index"); + throw new IllegalStateException("Could not find free color index"); } private static final class CustomColor extends HSSFColor { diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFRow.java index 9220c14157..a64840eed2 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFRow.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFRow.java @@ -171,10 +171,10 @@ public final class HSSFRow implements Row, Comparable { int column=cell.getColumnIndex(); if(column < 0) { - throw new RuntimeException("Negative cell indexes not allowed"); + throw new IllegalStateException("Negative cell indexes not allowed"); } if(column >= cells.length || cell != cells[column]) { - throw new RuntimeException("Specified cell is not from this row"); + throw new IllegalStateException("Specified cell is not from this row"); } if(cell.isPartOfArrayFormulaGroup()){ cell.tryToDeleteArrayFormula(null); diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 4a48d6fc21..c8e3c9bad3 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -227,7 +227,7 @@ public final class HSSFSheet implements Sheet { // Excel, OpenOffice.org and GoogleDocs are all OK with this, so POI should be too. if (rowRecordsAlreadyPresent) { // if at least one row record is present, all should be present. - throw new RuntimeException("Unexpected missing row when some rows already present"); + throw new IllegalStateException("Unexpected missing row when some rows already present"); }*/ // create the row record on the fly now. diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 82877661d7..cef0edaa37 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -1156,7 +1156,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { for (int defNameIndex = 0; defNameIndex < names.size(); defNameIndex++) { NameRecord r = workbook.getNameRecord(defNameIndex); if (r == null) { - throw new RuntimeException("Unable to find all defined names to iterate over"); + throw new IllegalStateException("Unable to find all defined names to iterate over"); } if (!r.isBuiltInName() || r.getBuiltInName() != builtinCode) { continue; diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java index 6bf3b6ca87..2ccb1135ba 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java @@ -59,7 +59,7 @@ final class StaticFontMetrics { try { fontMetricsProps = loadMetrics(); } catch (IOException e) { - throw new RuntimeException("Could not load font metrics", e); + throw new IllegalStateException("Could not load font metrics", e); } } diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java b/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java index ea3159c911..ef1622c40f 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java @@ -236,7 +236,7 @@ public abstract class ChunkedCipherInputStream extends LittleEndianInputStream { } } catch (IOException e) { // need to wrap checked exception, because of LittleEndianInput interface :( - throw new RuntimeException(e); + throw new IllegalStateException(e); } } diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/DirectoryNode.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/DirectoryNode.java index cd3a1bc134..54fab5f498 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/DirectoryNode.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/DirectoryNode.java @@ -232,7 +232,7 @@ public class DirectoryNode _filesystem.remove(entry); } catch (IOException e) { // TODO Work out how to report this, given we can't change the method signature... - throw new RuntimeException(e); + throw new IllegalStateException(e); } } return rval; diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/EntryUtils.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/EntryUtils.java index b6a24873c3..7c60176fcc 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/EntryUtils.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/EntryUtils.java @@ -238,7 +238,7 @@ public final class EntryUtils { return isEqual(inpA, inpB); } } catch (NoPropertySetStreamException | IOException ex) { - throw new RuntimeException(ex); + throw new IllegalStateException(ex); } } diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java index 8bb572e312..727030bf15 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java @@ -370,7 +370,7 @@ public class POIFSFileSystem extends BlockStore stream.close(); } catch (IOException e) { if (success) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } // else not success? Try block did not complete normally // just print stack trace and leave original ex to be thrown diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSStream.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSStream.java index f34d4da6ab..43d6b3b32c 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSStream.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSStream.java @@ -158,7 +158,7 @@ public class POIFSStream implements Iterable try { this.loopDetector = blockStore.getChainLoopDetector(); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -194,7 +194,7 @@ public class POIFSStream implements Iterable try { this.loopDetector = blockStore.getChainLoopDetector(); } catch(IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -213,7 +213,7 @@ public class POIFSStream implements Iterable nextBlock = blockStore.getNextBlock(nextBlock); return data; } catch(IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/TempFilePOIFSFileSystem.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/TempFilePOIFSFileSystem.java index 51c453faf8..175884c5f8 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/TempFilePOIFSFileSystem.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/TempFilePOIFSFileSystem.java @@ -41,7 +41,7 @@ public class TempFilePOIFSFileSystem extends POIFSFileSystem { tempFile = TempFile.createTempFile("poifs", ".tmp"); _data = new FileBackedDataSource(tempFile, false); } catch (IOException e) { - throw new RuntimeException("Failed to create data source", e); + throw new IllegalStateException("Failed to create data source", e); } } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/SLGraphics.java b/poi/src/main/java/org/apache/poi/sl/draw/SLGraphics.java index 9d0398e585..fe7afec9eb 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/SLGraphics.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/SLGraphics.java @@ -1659,7 +1659,7 @@ public class SLGraphics extends Graphics2D implements Cloneable { try { return (Graphics)clone(); } catch (CloneNotSupportedException e){ - throw new RuntimeException(e); + throw new IllegalStateException(e); } } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/PresetGeometries.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/PresetGeometries.java index 0f5a490274..58ef4ee870 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/PresetGeometries.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/PresetGeometries.java @@ -59,7 +59,7 @@ public final class PresetGeometries { } } } catch (IOException | XMLStreamException e){ - throw new RuntimeException(e); + throw new IllegalStateException(e); } } diff --git a/poi/src/main/java/org/apache/poi/ss/format/SimpleFraction.java b/poi/src/main/java/org/apache/poi/ss/format/SimpleFraction.java index f781cd71f7..41f1d07fea 100644 --- a/poi/src/main/java/org/apache/poi/ss/format/SimpleFraction.java +++ b/poi/src/main/java/org/apache/poi/ss/format/SimpleFraction.java @@ -110,7 +110,7 @@ public class SimpleFraction { return new SimpleFraction((int)p1, (int)q1); } if ((p2 > overflow) || (q2 > overflow)) { - throw new RuntimeException("Overflow trying to convert "+value+" to fraction ("+p2+"/"+q2+")"); + throw new IllegalStateException("Overflow trying to convert "+value+" to fraction ("+p2+"/"+q2+")"); } double convergent = (double)p2 / (double)q2; @@ -127,7 +127,7 @@ public class SimpleFraction { } while (!stop); if (n >= maxIterations) { - throw new RuntimeException("Unable to convert "+value+" to fraction after "+maxIterations+" iterations"); + throw new IllegalStateException("Unable to convert "+value+" to fraction after "+maxIterations+" iterations"); } if (q2 < maxDenominator) { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java b/poi/src/main/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java index 1e2387b4ce..446149b113 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java @@ -130,7 +130,7 @@ public final class CollaboratingWorkbooksEnvironment { for (WorkbookEvaluator evaluator : evaluators) { if (evalListener != evaluator.getEvaluationListener()) { // This would be very complex to support - throw new RuntimeException("Workbook evaluators must all have the same evaluation listener"); + throw new IllegalStateException("Workbook evaluators must all have the same evaluation listener"); } } EvaluationCache cache = new EvaluationCache(evalListener); diff --git a/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java b/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java index 61993d676b..f824ca49da 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java @@ -214,10 +214,10 @@ public final class FormulaParser { } /** Read New Character From Input Stream */ - private void GetChar() { + private void nextChar() { // The intersection operator is a space. We track whether the run of // whitespace preceding "look" counts as an intersection operator. - if (IsWhite(look)) { + if (isWhite(look)) { if (look == ' ') { _inIntersection = true; } @@ -228,7 +228,7 @@ public final class FormulaParser { // Check to see if we've walked off the end of the string. if (_pointer > _formulaLength) { - throw new RuntimeException("Parsed past the end of the formula, pos: " + _pointer + + throw new IllegalStateException("Parsed past the end of the formula, pos: " + _pointer + ", length: " + _formulaLength + ", formula: " + _formulaString); } if (_pointer < _formulaLength) { @@ -275,24 +275,24 @@ public final class FormulaParser { } /** Recognize an Alpha Character */ - private static boolean IsAlpha(int c) { + private static boolean isAlpha(int c) { return Character.isLetter(c) || c == '$' || c=='_'; } /** Recognize a Decimal Digit */ - private static boolean IsDigit(int c) { + private static boolean isDigit(int c) { return Character.isDigit(c); } /** Recognize White Space */ - private static boolean IsWhite(int c) { + private static boolean isWhite(int c) { return c ==' ' || c== TAB || c == CR || c == LF; } /** Skip Over Leading White Space */ - private void SkipWhite() { - while (IsWhite(look)) { - GetChar(); + private void skipWhite() { + while (isWhite(look)) { + nextChar(); } } @@ -301,7 +301,7 @@ public final class FormulaParser { * unchecked exception. This method does not consume whitespace (before or after the * matched character). */ - private void Match(int x) { + private void match(int x) { if (look != x) { throw expected(new StringBuilder() .append("'") @@ -309,16 +309,16 @@ public final class FormulaParser { .append("'") .toString()); } - GetChar(); + nextChar(); } /** Get a Number */ - private String GetNum() { + private String nextNum() { StringBuilder value = new StringBuilder(); - while (IsDigit(this.look)){ + while (isDigit(this.look)){ value.appendCodePoint(this.look); - GetChar(); + nextChar(); } return value.length() == 0 ? null : value.toString(); } @@ -328,7 +328,7 @@ public final class FormulaParser { boolean hasRange = false; while (look == ':') { int pos = _pointer; - GetChar(); + nextChar(); ParseNode nextPart = parseRangeable(); // Note - no range simplification here. An expr like "A1:B2:C3:D4:E5" should be // grouped into area ref pairs like: "(A1:B2):(C3:D4):E5" @@ -464,14 +464,14 @@ public final class FormulaParser { * */ private ParseNode parseRangeable() { - SkipWhite(); + skipWhite(); int savePointer = _pointer; SheetIdentifier sheetIden = parseSheetName(false); if (sheetIden == null) { resetPointer(savePointer); } else { - SkipWhite(); + skipWhite(); savePointer = _pointer; } @@ -497,15 +497,15 @@ public final class FormulaParser { } return parseNonRange(savePointer); } - boolean whiteAfterPart1 = IsWhite(look); + boolean whiteAfterPart1 = isWhite(look); if (whiteAfterPart1) { - SkipWhite(); + skipWhite(); } if (look == ':') { int colonPos = _pointer; - GetChar(); - SkipWhite(); + nextChar(); + skipWhite(); SimpleRangePart part2 = parseSimpleRangePart(); if (part2 != null && !part1.isCompatibleForArea(part2)) { // second part is not compatible with an area ref e.g. S!A1:S!B2 @@ -529,15 +529,15 @@ public final class FormulaParser { } if (look == '.') { - GetChar(); + nextChar(); int dotCount = 1; while (look =='.') { dotCount ++; - GetChar(); + nextChar(); } - boolean whiteBeforePart2 = IsWhite(look); + boolean whiteBeforePart2 = isWhite(look); - SkipWhite(); + skipWhite(); SimpleRangePart part2 = parseSimpleRangePart(); String part1And2 = _formulaString.substring(savePointer-1, _pointer-1); if (part2 == null) { @@ -635,7 +635,7 @@ public final class FormulaParser { // Do NOT return before done reading all the structured reference tokens from the input stream. // Throwing exceptions is okay. int savePtr0 = _pointer; - GetChar(); + nextChar(); boolean isTotalsSpec = false; boolean isThisRowSpec = false; @@ -671,16 +671,16 @@ public final class FormulaParser { } nSpecQuantifiers++; if (look == ','){ - GetChar(); + nextChar(); } else { break; } } boolean isThisRow = false; - SkipWhite(); + skipWhite(); if (look == '@') { isThisRow = true; - GetChar(); + nextChar(); } // parse column quantifier String endColumnName = null; @@ -694,7 +694,7 @@ public final class FormulaParser { if (look == ','){ throw new FormulaParseException("The formula "+ _formulaString + " is illegal: you should not use ',' with column quantifiers"); } else if (look == ':') { - GetChar(); + nextChar(); endColumnName = parseAsColumnQuantifier(); nColQuantifiers++; if (endColumnName == null) { @@ -738,7 +738,7 @@ public final class FormulaParser { } } } else { - Match(']'); + match(']'); } // Done reading from input stream // Ok to return now @@ -836,19 +836,19 @@ public final class FormulaParser { if ( look != '[') { return null; } - GetChar(); + nextChar(); if (look == '#') { return null; } if (look == '@') { - GetChar(); + nextChar(); } StringBuilder name = new StringBuilder(); while (look!=']') { name.appendCodePoint(look); - GetChar(); + nextChar(); } - Match(']'); + match(']'); return name.toString(); } /** @@ -859,16 +859,16 @@ public final class FormulaParser { if ( look != '[') { return null; } - GetChar(); + nextChar(); if( look != '#') { return null; } - GetChar(); + nextChar(); String name = parseAsName(); if ( name.equals("This")) { name = name + ' ' + parseAsName(); } - Match(']'); + match(']'); return name; } @@ -934,9 +934,9 @@ public final class FormulaParser { } while (isValidDefinedNameChar(look)) { sb.appendCodePoint(look); - GetChar(); + nextChar(); } - SkipWhite(); + skipWhite(); return sb.toString(); } @@ -1142,12 +1142,12 @@ public final class FormulaParser { private String getBookName() { StringBuilder sb = new StringBuilder(); - GetChar(); + nextChar(); while (look != ']') { sb.appendCodePoint(look); - GetChar(); + nextChar(); } - GetChar(); + nextChar(); return sb.toString(); } @@ -1165,7 +1165,7 @@ public final class FormulaParser { if (look == '\'' || isSndPartOfQuotedRange) { if (!isSndPartOfQuotedRange) { - Match('\''); + match('\''); } if (look == '[') @@ -1175,14 +1175,14 @@ public final class FormulaParser { boolean done = look == '\''; while(!done) { sb.appendCodePoint(look); - GetChar(); + nextChar(); switch (look){ case '\'' : { - GetChar(); + nextChar(); if (look == '\''){ // Any single quotes which were already present in the sheet name will be converted to double single quotes ('') // so switch back to single quote - GetChar(); + nextChar(); break; } } @@ -1193,9 +1193,9 @@ public final class FormulaParser { NameIdentifier iden = new NameIdentifier(sb.toString(), true); // quoted identifier - can't concatenate anything more - SkipWhite(); + skipWhite(); if (look == '!') { - GetChar(); + nextChar(); return new SheetIdentifier(bookName, iden); } // See if it's a multi-sheet range, eg Sheet1:Sheet3!A1 @@ -1211,15 +1211,15 @@ public final class FormulaParser { // can concatenate idens with dots while (isUnquotedSheetNameChar(look)) { sb.appendCodePoint(look); - GetChar(); + nextChar(); } if (look == '\'') { - GetChar(); + nextChar(); } NameIdentifier iden = new NameIdentifier(sb.toString(), false); - SkipWhite(); + skipWhite(); if (look == '!') { - GetChar(); + nextChar(); return new SheetIdentifier(bookName, iden); } // See if it's a multi-sheet range, eg Sheet1:Sheet3!A1 @@ -1230,7 +1230,7 @@ public final class FormulaParser { } if (look == '!' && bookName != null) { // Raw book reference, without a sheet - GetChar(); + nextChar(); return new SheetIdentifier(bookName, null); } return null; @@ -1241,7 +1241,7 @@ public final class FormulaParser { * Sheet1, see if it's actually a range eg Sheet1:Sheet2! */ private SheetIdentifier parseSheetRange(String bookname, NameIdentifier sheet1Name, boolean isSndPartOfQuotedRange) { - GetChar(); + nextChar(); SheetIdentifier sheet2 = parseSheetName(isSndPartOfQuotedRange); if (sheet2 != null) { return new SheetRangeIdentifier(bookname, sheet1Name, sheet2.getSheetIdentifier()); @@ -1290,7 +1290,7 @@ public final class FormulaParser { if(isFunc){ int savePointer = _pointer; resetPointer(_pointer + str.length()); - SkipWhite(); + skipWhite(); // open bracket indicates that the argument is a function, // the returning value should be false, i.e. "not a valid cell reference" result = look != '('; @@ -1356,9 +1356,9 @@ public final class FormulaParser { } } - Match('('); + match('('); ParseNode[] args = Arguments(); - Match(')'); + match(')'); return getFunction(name, nameToken, args); } @@ -1465,14 +1465,14 @@ public final class FormulaParser { private ParseNode[] Arguments() { //average 2 args per function List temp = new ArrayList<>(2); - SkipWhite(); + skipWhite(); if(look == ')') { return ParseNode.EMPTY_ARRAY; } boolean missedPrevArg = true; while (true) { - SkipWhite(); + skipWhite(); if (isArgumentDelimiter(look)) { if (missedPrevArg) { temp.add(new ParseNode(MissingArgPtg.instance)); @@ -1480,13 +1480,13 @@ public final class FormulaParser { if (look == ')') { break; } - Match(','); + match(','); missedPrevArg = true; continue; } temp.add(intersectionExpression()); missedPrevArg = false; - SkipWhite(); + skipWhite(); if (!isArgumentDelimiter(look)) { throw expected("',' or ')'"); } @@ -1500,11 +1500,11 @@ public final class FormulaParser { private ParseNode powerFactor() { ParseNode result = percentFactor(); while(true) { - SkipWhite(); + skipWhite(); if(look != '^') { return result; } - Match('^'); + match('^'); ParseNode other = percentFactor(); result = new ParseNode(PowerPtg.instance, result, other); } @@ -1513,11 +1513,11 @@ public final class FormulaParser { private ParseNode percentFactor() { ParseNode result = parseSimpleFactor(); while(true) { - SkipWhite(); + skipWhite(); if(look != '%') { return result; } - Match('%'); + match('%'); result = new ParseNode(PercentPtg.instance, result); } } @@ -1527,32 +1527,32 @@ public final class FormulaParser { * factors (without ^ or % ) */ private ParseNode parseSimpleFactor() { - SkipWhite(); + skipWhite(); switch(look) { case '#': return new ParseNode(ErrPtg.valueOf(parseErrorLiteral())); case '-': - Match('-'); + match('-'); return parseUnary(false); case '+': - Match('+'); + match('+'); return parseUnary(true); case '(': - Match('('); + match('('); ParseNode inside = unionExpression(); - Match(')'); + match(')'); return new ParseNode(ParenthesisPtg.instance, inside); case '"': return new ParseNode(new StringPtg(parseStringLiteral())); case '{': - Match('{'); + match('{'); ParseNode arrayNode = parseArray(); - Match('}'); + match('}'); return arrayNode; } // named ranges and tables can start with underscore or backslash // see https://support.office.com/en-us/article/Define-and-use-names-in-formulas-4d0f13ac-53b7-422e-afd2-abd7ff379c64?ui=en-US&rs=en-US&ad=US#bmsyntax_rules_for_names - if (IsAlpha(look) || Character.isDigit(look) || look == '\'' || look == '[' || look == '_' || look == '\\' ) { + if (isAlpha(look) || Character.isDigit(look) || look == '\'' || look == '[' || look == '_' || look == '\\' ) { return parseRangeExpression(); } if (look == '.') { @@ -1564,7 +1564,7 @@ public final class FormulaParser { private ParseNode parseUnary(boolean isPlus) { - boolean numberFollows = IsDigit(look) || look=='.'; + boolean numberFollows = isDigit(look) || look=='.'; ParseNode factor = powerFactor(); if (numberFollows) { @@ -1602,7 +1602,7 @@ public final class FormulaParser { if (look != ';') { throw expected("'}' or ';'"); } - Match(';'); + match(';'); } int nRows = rowsData.size(); Object[][] values2d = new Object[nRows][]; @@ -1626,13 +1626,13 @@ public final class FormulaParser { List temp = new ArrayList<>(); while (true) { temp.add(parseArrayItem()); - SkipWhite(); + skipWhite(); switch(look) { case '}': case ';': break; case ',': - Match(','); + match(','); continue; default: throw expected("'}' or ','"); @@ -1647,7 +1647,7 @@ public final class FormulaParser { } private Object parseArrayItem() { - SkipWhite(); + skipWhite(); switch(look) { case '"': return parseStringLiteral(); case '#': return ErrorConstant.valueOf(parseErrorLiteral()); @@ -1655,8 +1655,8 @@ public final class FormulaParser { case 'T': case 't': return parseBooleanLiteral(); case '-': - Match('-'); - SkipWhite(); + match('-'); + skipWhite(); return convertArrayNumber(parseNumber(), false); } // else assume number @@ -1681,7 +1681,7 @@ public final class FormulaParser { } else if (ptg instanceof NumberPtg) { value = ((NumberPtg)ptg).getValue(); } else { - throw new RuntimeException("Unexpected ptg (" + ptg.getClass().getName() + ")"); + throw new IllegalStateException("Unexpected ptg (" + ptg.getClass().getName() + ")"); } if (!isPositive) { value = -value; @@ -1692,25 +1692,25 @@ public final class FormulaParser { private Ptg parseNumber() { String number2 = null; String exponent = null; - String number1 = GetNum(); + String number1 = nextNum(); if (look == '.') { - GetChar(); - number2 = GetNum(); + nextChar(); + number2 = nextNum(); } if (look == 'E') { - GetChar(); + nextChar(); String sign = ""; if (look == '+') { - GetChar(); + nextChar(); } else if (look == '-') { - GetChar(); + nextChar(); sign = "-"; } - String number = GetNum(); + String number = nextNum(); if (number == null) { throw expected("Integer"); } @@ -1726,7 +1726,7 @@ public final class FormulaParser { private int parseErrorLiteral() { - Match('#'); + match('#'); String part1 = parseUnquotedIdentifier(); if (part1 == null) { throw expected("remainder of error constant literal"); @@ -1737,7 +1737,7 @@ public final class FormulaParser { case 'V': { FormulaError fe = FormulaError.VALUE; if(part1.equals(fe.name())) { - Match('!'); + match('!'); return fe.getCode(); } throw expected(fe.getString()); @@ -1745,7 +1745,7 @@ public final class FormulaParser { case 'R': { FormulaError fe = FormulaError.REF; if(part1.equals(fe.name())) { - Match('!'); + match('!'); return fe.getCode(); } throw expected(fe.getString()); @@ -1753,9 +1753,9 @@ public final class FormulaParser { case 'D': { FormulaError fe = FormulaError.DIV0; if(part1.equals("DIV")) { - Match('/'); - Match('0'); - Match('!'); + match('/'); + match('0'); + match('!'); return fe.getCode(); } throw expected(fe.getString()); @@ -1764,26 +1764,26 @@ public final class FormulaParser { FormulaError fe = FormulaError.NAME; if(part1.equals(fe.name())) { // only one that ends in '?' - Match('?'); + match('?'); return fe.getCode(); } fe = FormulaError.NUM; if(part1.equals(fe.name())) { - Match('!'); + match('!'); return fe.getCode(); } fe = FormulaError.NULL; if(part1.equals(fe.name())) { - Match('!'); + match('!'); return fe.getCode(); } fe = FormulaError.NA; if(part1.equals("N")) { - Match('/'); + match('/'); if(look != 'A' && look != 'a') { throw expected(fe.getString()); } - Match(look); + match(look); // Note - no '!' or '?' suffix return fe.getCode(); } @@ -1800,7 +1800,7 @@ public final class FormulaParser { StringBuilder sb = new StringBuilder(); while (Character.isLetterOrDigit(look) || look == '.') { sb.appendCodePoint(look); - GetChar(); + nextChar(); } if (sb.length() < 1) { return null; @@ -1854,18 +1854,18 @@ public final class FormulaParser { private String parseStringLiteral() { - Match('"'); + match('"'); StringBuilder token = new StringBuilder(); while (true) { if (look == '"') { - GetChar(); + nextChar(); if (look != '"') { break; } } token.appendCodePoint(look); - GetChar(); + nextChar(); } return token.toString(); } @@ -1874,15 +1874,15 @@ public final class FormulaParser { private ParseNode Term() { ParseNode result = powerFactor(); while(true) { - SkipWhite(); + skipWhite(); Ptg operator; switch(look) { case '*': - Match('*'); + match('*'); operator = MultiplyPtg.instance; break; case '/': - Match('/'); + match('/'); operator = DividePtg.instance; break; default: @@ -1897,9 +1897,9 @@ public final class FormulaParser { ParseNode result = intersectionExpression(); boolean hasUnions = false; while (true) { - SkipWhite(); + skipWhite(); if (look == ',') { - GetChar(); + nextChar(); hasUnions = true; ParseNode other = intersectionExpression(); result = new ParseNode(UnionPtg.instance, result, other); @@ -1916,7 +1916,7 @@ public final class FormulaParser { ParseNode result = comparisonExpression(); boolean hasIntersections = false; while (true) { - SkipWhite(); + skipWhite(); if (_inIntersection) { int savePointer = _pointer; @@ -1942,7 +1942,7 @@ public final class FormulaParser { private ParseNode comparisonExpression() { ParseNode result = concatExpression(); while (true) { - SkipWhite(); + skipWhite(); switch(look) { case '=': case '>': @@ -1958,24 +1958,24 @@ public final class FormulaParser { private Ptg getComparisonToken() { if(look == '=') { - Match(look); + match(look); return EqualPtg.instance; } boolean isGreater = look == '>'; - Match(look); + match(look); if(isGreater) { if(look == '=') { - Match('='); + match('='); return GreaterEqualPtg.instance; } return GreaterThanPtg.instance; } switch(look) { case '=': - Match('='); + match('='); return LessEqualPtg.instance; case '>': - Match('>'); + match('>'); return NotEqualPtg.instance; } return LessThanPtg.instance; @@ -1985,11 +1985,11 @@ public final class FormulaParser { private ParseNode concatExpression() { ParseNode result = additiveExpression(); while (true) { - SkipWhite(); + skipWhite(); if(look != '&') { break; // finished with concat expression } - Match('&'); + match('&'); ParseNode other = additiveExpression(); result = new ParseNode(ConcatPtg.instance, result, other); } @@ -2001,15 +2001,15 @@ public final class FormulaParser { private ParseNode additiveExpression() { ParseNode result = Term(); while (true) { - SkipWhite(); + skipWhite(); Ptg operator; switch(look) { case '+': - Match('+'); + match('+'); operator = AddPtg.instance; break; case '-': - Match('-'); + match('-'); operator = SubtractPtg.instance; break; default: @@ -2040,7 +2040,7 @@ end; */ private void parse() { _pointer=0; - GetChar(); + nextChar(); _rootNode = unionExpression(); if(_pointer <= _formulaLength) { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/FormulaRenderer.java b/poi/src/main/java/org/apache/poi/ss/formula/FormulaRenderer.java index 599d8fb6f5..01d46df866 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/FormulaRenderer.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/FormulaRenderer.java @@ -81,7 +81,7 @@ public class FormulaRenderer { stack.push(attrPtg.toFormulaString(operands)); continue; } - throw new RuntimeException("Unexpected tAttr: " + attrPtg); + throw new IllegalStateException("Unexpected tAttr: " + attrPtg); } if (ptg instanceof WorkbookDependentFormula) { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/OperandClassTransformer.java b/poi/src/main/java/org/apache/poi/ss/formula/OperandClassTransformer.java index 732ee145be..786181c6cd 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/OperandClassTransformer.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/OperandClassTransformer.java @@ -79,7 +79,7 @@ final class OperandClassTransformer { rootNodeOperandClass = Ptg.CLASS_REF; break; default: - throw new RuntimeException("Incomplete code - formula type (" + throw new IllegalStateException("Incomplete code - formula type (" + _formulaType + ") not supported yet"); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluationContext.java b/poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluationContext.java index 618200ec65..b22e18e55f 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluationContext.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluationContext.java @@ -134,7 +134,7 @@ public final class OperationEvaluationContext { try { targetEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName); } catch (WorkbookNotFoundException e) { - throw new RuntimeException(e.getMessage(), e); + throw new IllegalStateException(e.getMessage(), e); } otherFirstSheetIndex = targetEvaluator.getSheetIndex(externalSheet.getSheetName()); @@ -144,7 +144,7 @@ public final class OperationEvaluationContext { } if (otherFirstSheetIndex < 0) { - throw new RuntimeException("Invalid sheet name '" + externalSheet.getSheetName() + throw new IllegalStateException("Invalid sheet name '" + externalSheet.getSheetName() + "' in bool '" + workbookName + "'."); } } @@ -227,11 +227,11 @@ public final class OperationEvaluationContext { case NAMED_RANGE: EvaluationName nm = _workbook.getName(refStrPart1, _sheetIndex); if (nm == null) { - throw new RuntimeException("Specified name '" + refStrPart1 + + throw new IllegalStateException("Specified name '" + refStrPart1 + "' is not found in the workbook (sheetIndex=" + _sheetIndex + ")."); } if (!nm.isRange()) { - throw new RuntimeException("Specified name '" + refStrPart1 + "' is not a range as expected."); + throw new IllegalStateException("Specified name '" + refStrPart1 + "' is not a range as expected."); } return _bookEvaluator.evaluateNameFormula(nm.getNameDefinition(), this); } @@ -298,7 +298,7 @@ public final class OperationEvaluationContext { case BAD_CELL_OR_NAMED_RANGE: return ErrorEval.REF_INVALID; case NAMED_RANGE: - throw new RuntimeException("Cannot evaluate '" + refStrPart1 + throw new IllegalStateException("Cannot evaluate '" + refStrPart1 + "'. Indirect evaluation of defined names not supported yet"); } @@ -417,7 +417,7 @@ public final class OperationEvaluationContext { private ValueEval convertObjectEval(Object token) { if (token == null) { - throw new RuntimeException("Array item cannot be null"); + throw new IllegalStateException("Array item cannot be null"); } if (token instanceof String) { return new StringEval((String) token); @@ -533,7 +533,7 @@ public final class OperationEvaluationContext { EvaluationName evaluationName = refWorkbookEvaluator.getName(externName.getName(), externName.getIx() - 1); if (evaluationName != null && evaluationName.hasFormula()) { if (evaluationName.getNameDefinition().length > 1) { - throw new RuntimeException("Complex name formulas not supported yet"); + throw new IllegalStateException("Complex name formulas not supported yet"); } // Need to evaluate the reference in the context of the other book diff --git a/poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java b/poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java index 0ee0b23e50..cf12bbc66b 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java @@ -135,7 +135,7 @@ final class OperationEvaluatorFactory { return udfFunc.evaluate(args, ec); } - throw new RuntimeException("Unexpected operation ptg class (" + ptg.getClass().getName() + ")"); + throw new IllegalStateException("Unexpected operation ptg class (" + ptg.getClass().getName() + ")"); } static ValueEval evaluateArrayFunction(ArrayFunction func, ValueEval[] args, diff --git a/poi/src/main/java/org/apache/poi/ss/formula/SheetNameFormatter.java b/poi/src/main/java/org/apache/poi/ss/formula/SheetNameFormatter.java index 11f3e0802b..26eca119c1 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/SheetNameFormatter.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/SheetNameFormatter.java @@ -68,7 +68,7 @@ public final class SheetNameFormatter { appendAndEscape(out, rawSheetName); } } catch (Exception e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -96,7 +96,7 @@ public final class SheetNameFormatter { appendOrREF(out, rawSheetName); } } catch (Exception e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -125,7 +125,7 @@ public final class SheetNameFormatter { sb.append(ch); } } catch (Exception e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -196,7 +196,7 @@ public final class SheetNameFormatter { case '\n': case '\r': case '\t': - throw new RuntimeException("Illegal character (0x" + throw new IllegalStateException("Illegal character (0x" + Integer.toHexString(ch) + ") found in sheet name"); } return true; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/UserDefinedFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/UserDefinedFunction.java index 10a2a1c8bf..c0c0cc56fb 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/UserDefinedFunction.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/UserDefinedFunction.java @@ -36,11 +36,20 @@ final class UserDefinedFunction implements FreeRefFunction { // enforce singleton } + /** + * @param args the pre-evaluated arguments for this function. args is never {@code null}, + * nor are any of its elements. + * @param ec primarily used to identify the source cell containing the formula being evaluated. + * may also be used to dynamically create reference evals. + * @return value + * @throws IllegalStateException if first arg is not a {@link FunctionNameEval} + * @throws NotImplementedFunctionException if function is not implemented + */ @Override public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { int nIncomingArgs = args.length; - if(nIncomingArgs < 1) { - throw new RuntimeException("function name argument missing"); + if (nIncomingArgs < 1) { + throw new IllegalStateException("function name argument missing"); } ValueEval nameArg = args[0]; @@ -48,7 +57,7 @@ final class UserDefinedFunction implements FreeRefFunction { if (nameArg instanceof FunctionNameEval) { functionName = ((FunctionNameEval) nameArg).getFunctionName(); } else { - throw new RuntimeException("First argument should be a NameEval, but got (" + throw new IllegalStateException("First argument should be a NameEval, but got (" + nameArg.getClass().getName() + ")"); } FreeRefFunction targetFunc = ec.findUserDefinedFunction(functionName); diff --git a/poi/src/main/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/poi/src/main/java/org/apache/poi/ss/formula/WorkbookEvaluator.java index 8a8d391662..2d22023426 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/WorkbookEvaluator.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/WorkbookEvaluator.java @@ -192,7 +192,7 @@ public final class WorkbookEvaluator { if (result == null) { int sheetIndex = _workbook.getSheetIndex(sheet); if (sheetIndex < 0) { - throw new RuntimeException("Specified sheet from a different book"); + throw new IllegalStateException("Specified sheet from a different book"); } result = sheetIndex; _sheetIndexesBySheet.put(sheet, result); @@ -292,7 +292,7 @@ public final class WorkbookEvaluator { break; case FORMULA: default: - throw new RuntimeException("Unexpected cell type '" + srcCell.getCellType() + "' found!"); + throw new IllegalStateException("Unexpected cell type '" + srcCell.getCellType() + "' found!"); } } else { throw re; @@ -362,7 +362,7 @@ public final class WorkbookEvaluator { case ERROR: return ErrorEval.valueOf(cell.getErrorCellValue()); default: - throw new RuntimeException("Unexpected cell type (" + cellType + ")"); + throw new IllegalStateException("Unexpected cell type (" + cellType + ")"); } } @@ -542,7 +542,7 @@ public final class WorkbookEvaluator { opResult = getEvalForPtg(ptg, ec); } if (opResult == null) { - throw new RuntimeException("Evaluation result must not be null"); + throw new IllegalStateException("Evaluation result must not be null"); } // logDebug("push " + opResult); stack.push(opResult); @@ -588,11 +588,11 @@ public final class WorkbookEvaluator { while (remBytes != 0) { index++; if (index >= ptgs.length) { - throw new RuntimeException("Skip distance too far (ran out of formula tokens)."); + throw new IllegalStateException("Skip distance too far (ran out of formula tokens)."); } remBytes -= ptgs[index].getSize(); if (remBytes < 0) { - throw new RuntimeException("Bad skip distance (wrong token size calculation)."); + throw new IllegalStateException("Bad skip distance (wrong token size calculation)."); } } return index - startIndex; @@ -738,15 +738,15 @@ public final class WorkbookEvaluator { // POI uses UnknownPtg when the encoded Ptg array seems to be corrupted. // This seems to occur in very rare cases (e.g. unused name formulas in bug 44774, attachment 21790) // In any case, formulas are re-parsed before execution, so UnknownPtg should not get here - throw new RuntimeException("UnknownPtg not allowed"); + throw new IllegalStateException("UnknownPtg not allowed"); } if (ptg instanceof ExpPtg) { // ExpPtg is used for array formulas and shared formulas. // it is currently unsupported, and may not even get implemented here - throw new RuntimeException("ExpPtg currently not supported"); + throw new IllegalStateException("ExpPtg currently not supported"); } - throw new RuntimeException("Unexpected ptg class (" + ptg.getClass().getName() + ")"); + throw new IllegalStateException("Unexpected ptg class (" + ptg.getClass().getName() + ")"); } private ValueEval processNameEval(ValueEval eval, OperationEvaluationContext ec) { @@ -765,7 +765,7 @@ public final class WorkbookEvaluator { return evaluateNameFormula(nameRecord.getNameDefinition(), ec); } - throw new RuntimeException("Don't know how to evaluate name '" + nameRecord.getNameText() + "'"); + throw new IllegalStateException("Don't know how to evaluate name '" + nameRecord.getNameText() + "'"); } /** diff --git a/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java b/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java index 60546cf051..ea477bd01f 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java @@ -258,7 +258,7 @@ final class YearFracCalculator { case 23: // transition from daylight savings adjusted to normal time // Unexpected since we are using UTC_TIME_ZONE default: - throw new RuntimeException("Unexpected date diff between " + startDateMS + " and " + endDateMS); + throw new IllegalStateException("Unexpected date diff between " + startDateMS + " and " + endDateMS); } return (int) (0.5 + ((double)msDiff / MS_PER_DAY)); diff --git a/poi/src/main/java/org/apache/poi/ss/formula/eval/ErrorEval.java b/poi/src/main/java/org/apache/poi/ss/formula/eval/ErrorEval.java index 31d08d05e5..c4dd9eed84 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/eval/ErrorEval.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/eval/ErrorEval.java @@ -60,7 +60,7 @@ public final class ErrorEval implements ValueEval { if (eval != null) { return eval; } else { - throw new RuntimeException("Unhandled error type for code " + errorCode); + throw new IllegalStateException("Unhandled error type for code " + errorCode); } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java b/poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java index 38f43137cc..5619b70fbe 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java @@ -267,7 +267,7 @@ public final class OperandResolver { } return dd; } - throw new RuntimeException("Unexpected arg eval type (" + ev.getClass().getName() + ")"); + throw new IllegalStateException("Unexpected arg eval type (" + ev.getClass().getName() + ")"); } /** @@ -368,6 +368,6 @@ public final class OperandResolver { if (ve instanceof ErrorEval) { throw new EvaluationException((ErrorEval) ve); } - throw new RuntimeException("Unexpected eval (" + ve.getClass().getName() + ")"); + throw new IllegalStateException("Unexpected eval (" + ve.getClass().getName() + ")"); } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java b/poi/src/main/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java index e864294ab8..cd3294f550 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java @@ -98,7 +98,7 @@ final class ForkedEvaluationCell implements EvaluationCell { private void checkCellType(CellType expectedCellType) { if (_cellType != expectedCellType) { - throw new RuntimeException("Wrong data type (" + _cellType + ")"); + throw new IllegalStateException("Wrong data type (" + _cellType + ")"); } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java b/poi/src/main/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java index 564b5da403..1789381d6e 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java @@ -98,7 +98,7 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook { public Ptg[] getFormulaTokens(EvaluationCell cell) { if (cell instanceof ForkedEvaluationCell) { // doesn't happen yet because formulas cannot be modified from the master workbook - throw new RuntimeException("Updated formulas not supported yet"); + throw new IllegalStateException("Updated formulas not supported yet"); } return _masterBook.getFormulaTokens(cell); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionDataBuilder.java b/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionDataBuilder.java index 6baef59ef9..108f91c0f1 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionDataBuilder.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionDataBuilder.java @@ -56,14 +56,14 @@ final class FunctionDataBuilder { prevFM = _functionDataByName.get(functionName); if(prevFM != null) { if(!hasFootnote || !_mutatingFunctionIndexes.contains(indexKey)) { - throw new RuntimeException("Multiple entries for function name '" + functionName + "'"); + throw new IllegalStateException("Multiple entries for function name '" + functionName + "'"); } _functionDataByIndex.remove(prevFM.getIndex()); } prevFM = _functionDataByIndex.get(indexKey); if(prevFM != null) { if(!hasFootnote || !_mutatingFunctionIndexes.contains(indexKey)) { - throw new RuntimeException("Multiple entries for function index (" + functionIndex + ")"); + throw new IllegalStateException("Multiple entries for function index (" + functionIndex + ")"); } _functionDataByName.remove(prevFM.getName()); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java b/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java index e7949ecc92..b03c732e89 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java @@ -85,7 +85,7 @@ final class FunctionMetadataReader { private static void readResourceFile(FunctionDataBuilder fdb, String resourceFile) { try (InputStream is = FunctionMetadataReader.class.getResourceAsStream(resourceFile)) { if (is == null) { - throw new RuntimeException("resource '" + resourceFile + "' not found"); + throw new IllegalStateException("resource '" + resourceFile + "' not found"); } try(BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { @@ -106,7 +106,7 @@ final class FunctionMetadataReader { } } } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -114,7 +114,7 @@ final class FunctionMetadataReader { String[] parts = TAB_DELIM_PATTERN.split(line, -2); if(parts.length != 8) { - throw new RuntimeException("Bad line format '" + line + "' - expected 8 data fields delimited by tab, " + + throw new IllegalStateException("Bad line format '" + line + "' - expected 8 data fields delimited by tab, " + "but had " + parts.length + ": " + Arrays.toString(parts)); } int functionIndex = parseInt(parts[0]); @@ -168,7 +168,7 @@ final class FunctionMetadataReader { private static byte parseOperandTypeCode(String code) { if(code.length() != 1) { - throw new RuntimeException("Bad operand type code format '" + code + "' expected single char"); + throw new IllegalStateException("Bad operand type code format '" + code + "' expected single char"); } switch(code.charAt(0)) { case 'V': return Ptg.CLASS_VALUE; @@ -197,7 +197,7 @@ final class FunctionMetadataReader { if(DIGIT_ENDING_FUNCTION_NAMES_SET.contains(functionName)) { return; } - throw new RuntimeException("Invalid function name '" + functionName + throw new IllegalStateException("Invalid function name '" + functionName + "' (is footnote number incorrectly appended)"); } @@ -205,7 +205,7 @@ final class FunctionMetadataReader { try { return Integer.parseInt(valStr); } catch (NumberFormatException e) { - throw new RuntimeException("Value '" + valStr + "' could not be parsed as an integer"); + throw new IllegalStateException("Value '" + valStr + "' could not be parsed as an integer"); } } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/ArrayFunctionUtils.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/ArrayFunctionUtils.java index 3dbedd2ae6..37891fe7fd 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/ArrayFunctionUtils.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/ArrayFunctionUtils.java @@ -129,7 +129,7 @@ final class ArrayFunctionUtils { if (ve == BlankEval.instance) { return null; } - throw new RuntimeException("Invalid ValueEval type passed for conversion: (" + throw new IllegalStateException("Invalid ValueEval type passed for conversion: (" + ve.getClass() + ")"); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Countif.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Countif.java index 85444596d5..93fdf033a4 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Countif.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Countif.java @@ -119,7 +119,7 @@ public final class Countif extends Fixed2ArgFunction { case NE: return !cmpResult; } - throw new RuntimeException("Cannot call boolean evaluate on non-equality operator '" + throw new IllegalStateException("Cannot call boolean evaluate on non-equality operator '" + _representation + "'"); } public boolean evaluate(int cmpResult) { @@ -133,7 +133,7 @@ public final class Countif extends Fixed2ArgFunction { case GT: return cmpResult > 0; case GE: return cmpResult >= 0; } - throw new RuntimeException("Cannot call boolean evaluate on non-equality operator '" + throw new IllegalStateException("Cannot call boolean evaluate on non-equality operator '" + _representation + "'"); } @Override @@ -477,7 +477,7 @@ public final class Countif extends Fixed2ArgFunction { if(evaluatedCriteriaArg == BlankEval.instance) { return null; } - throw new RuntimeException("Unexpected type for criteria (" + throw new IllegalStateException("Unexpected type for criteria (" + evaluatedCriteriaArg.getClass().getName() + ")"); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Index.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Index.java index 12a87f82b0..d8c484b593 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Index.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Index.java @@ -85,7 +85,7 @@ public final class Index implements Function2Arg, Function3Arg, Function4Arg, Ar @Override public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2, ValueEval arg3) { - throw new RuntimeException("Incomplete code" + throw new IllegalStateException("Incomplete code" + " - don't know how to support the 'area_num' parameter yet)"); // Excel expression might look like this "INDEX( (A1:B4, C3:D6, D2:E5 ), 1, 2, 3) // In this example, the 3rd area would be used i.e. D2:E5, and the overall result would be E2 @@ -103,7 +103,7 @@ public final class Index implements Function2Arg, Function3Arg, Function4Arg, Ar } // else the other variation of this function takes an array as the first argument // it seems like interface 'ArrayEval' does not even exist yet - throw new RuntimeException("Incomplete code - cannot handle first arg of type (" + throw new IllegalStateException("Incomplete code - cannot handle first arg of type (" + arg0.getClass().getName() + ")"); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Lookup.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Lookup.java index 8c2ff6f1af..8981676b68 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Lookup.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Lookup.java @@ -84,7 +84,7 @@ public final class Lookup extends Var2or3ArgFunction { ValueVector resultVector = createVector(aeResultVector); if(lookupVector.getSize() > resultVector.getSize()) { // Excel seems to handle this by accessing past the end of the result vector. - throw new RuntimeException("Lookup vector and result vector of differing sizes not supported yet"); + throw new IllegalStateException("Lookup vector and result vector of differing sizes not supported yet"); } int index = LookupUtils.lookupFirstIndexOfValue(lookupValue, lookupVector, true); @@ -100,6 +100,6 @@ public final class Lookup extends Var2or3ArgFunction { return result; } // extra complexity required to emulate the way LOOKUP can handles these abnormal cases. - throw new RuntimeException("non-vector lookup or result areas not supported yet"); + throw new IllegalStateException("non-vector lookup or result areas not supported yet"); } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java index c76bfc0f4e..d36ae34b7a 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java @@ -358,14 +358,14 @@ public final class LookupUtils { private final Class _targetClass; protected LookupValueComparerBase(ValueEval targetValue) { if(targetValue == null) { - throw new RuntimeException("targetValue cannot be null"); + throw new IllegalStateException("targetValue cannot be null"); } _targetClass = targetValue.getClass(); } @Override public final CompareResult compareTo(ValueEval other) { if (other == null) { - throw new RuntimeException("compare to value cannot be null"); + throw new IllegalStateException("compare to value cannot be null"); } if (_targetClass != other.getClass()) { return CompareResult.TYPE_MISMATCH; @@ -611,7 +611,7 @@ public final class LookupUtils { // zero is FALSE, everything else is TRUE return 0.0 != nve.getNumberValue(); } - throw new RuntimeException("Unexpected eval type (" + valEval + ")"); + throw new IllegalStateException("Unexpected eval type (" + valEval + ")"); } public static int lookupFirstIndexOfValue(ValueEval lookupValue, ValueVector vector, boolean isRangeLookup) throws EvaluationException { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Match.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Match.java index 6ba4a78235..b6bb093a22 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Match.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Match.java @@ -117,7 +117,7 @@ public final class Match extends Var2or3ArgFunction { @Override public ValueEval getItem(int index) { if (index != 0) { - throw new RuntimeException("Invalid index (" + throw new IllegalStateException("Invalid index (" + index + ") only zero is allowed"); } return _value; @@ -160,7 +160,7 @@ public final class Match extends Var2or3ArgFunction { // else looks like a number throw new EvaluationException(ErrorEval.NA); } - throw new RuntimeException("Unexpected eval type (" + eval + ")"); + throw new IllegalStateException("Unexpected eval type (" + eval + ")"); } @@ -191,7 +191,7 @@ public final class Match extends Var2or3ArgFunction { // uses the default-value instead return 1; } - throw new RuntimeException("Unexpected match_type type (" + match_type.getClass().getName() + ")"); + throw new IllegalStateException("Unexpected match_type type (" + match_type.getClass().getName() + ")"); } /** diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Mode.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Mode.java index a8fcdd7983..0c12531176 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Mode.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Mode.java @@ -128,6 +128,6 @@ public final class Mode implements Function { temp.add(Double.valueOf(((NumberEval) arg).getNumberValue())); return; } - throw new RuntimeException("Unexpected value type (" + arg.getClass().getName() + ")"); + throw new IllegalStateException("Unexpected value type (" + arg.getClass().getName() + ")"); } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java index 2723c7dc0c..8f8f6b8175 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java @@ -225,7 +225,7 @@ public abstract class MultiOperandNumericFunction implements Function { missingArgConsumer.accept((MissingArgEval) ve, temp); return; } - throw new RuntimeException("Invalid ValueEval type passed for conversion: (" + throw new IllegalStateException("Invalid ValueEval type passed for conversion: (" + ve.getClass() + ")"); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Offset.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Offset.java index 25567a108b..cd77d72c9b 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Offset.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Offset.java @@ -56,7 +56,7 @@ public final class Offset implements Function { public LinearOffsetRange(int offset, int length) { if(length == 0) { // handled that condition much earlier - throw new RuntimeException("length may not be zero"); + throw new IllegalStateException("length may not be zero"); } _offset = offset; _length = length; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java index 9345517d76..9aafaf0e41 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java @@ -87,7 +87,7 @@ public final class Sumproduct implements Function { } catch (EvaluationException e) { return e.getErrorEval(); } - throw new RuntimeException("Invalid arg type for SUMPRODUCT: (" + throw new IllegalStateException("Invalid arg type for SUMPRODUCT: (" + firstArg.getClass().getName() + ")"); } @@ -116,7 +116,7 @@ public final class Sumproduct implements Function { } if (eval == null) { - throw new RuntimeException("parameter may not be null"); + throw new IllegalStateException("parameter may not be null"); } if (eval instanceof AreaEval) { AreaEval ae = (AreaEval) eval; @@ -235,7 +235,7 @@ public final class Sumproduct implements Function { NumericValueEval nve = (NumericValueEval) ve; return nve.getNumberValue(); } - throw new RuntimeException("Unexpected value eval class (" + throw new IllegalStateException("Unexpected value eval class (" + ve.getClass().getName() + ")"); } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Trend.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Trend.java index 157663d0a1..a06e681701 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Trend.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Trend.java @@ -108,7 +108,7 @@ public final class Trend implements Function { eval = arg; } if (eval == null) { - throw new RuntimeException("Parameter may not be null."); + throw new IllegalStateException("Parameter may not be null."); } if (eval instanceof AreaEval) { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java index 5003f20be1..014c95ceb3 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java @@ -48,10 +48,10 @@ public abstract class AbstractFunctionPtg extends OperationPtg { protected AbstractFunctionPtg(int functionIndex, int pReturnClass, byte[] paramTypes, int nParams) { _numberOfArgs = nParams; if (functionIndex < Short.MIN_VALUE || functionIndex > Short.MAX_VALUE) - throw new RuntimeException("functionIndex " + functionIndex + " cannot be cast to short"); + throw new IllegalStateException("functionIndex " + functionIndex + " cannot be cast to short"); _functionIndex = (short) functionIndex; if (pReturnClass < Byte.MIN_VALUE || pReturnClass > Byte.MAX_VALUE) - throw new RuntimeException("pReturnClass " + pReturnClass + " cannot be cast to byte"); + throw new IllegalStateException("pReturnClass " + pReturnClass + " cannot be cast to byte"); returnClass = (byte) pReturnClass; paramClass = paramTypes; } @@ -140,7 +140,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg { fm = FunctionMetadataRegistry.getFunctionByIndex(index); } if(fm == null) { - throw new RuntimeException("bad function index (" + index + ", " + isCetab + ")"); + throw new IllegalStateException("bad function index (" + index + ", " + isCetab + ")"); } return fm.getName(); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java index 1f92d64108..c1b46286ad 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java @@ -107,7 +107,7 @@ public final class Area3DPtg extends AreaPtgBase implements WorkbookDependentFor @Override public String toFormulaString() { - throw new RuntimeException("3D references need a workbook to determine formula text"); + throw new IllegalStateException("3D references need a workbook to determine formula text"); } @Override diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java index 6014c54373..5d1e247e5a 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java @@ -192,7 +192,7 @@ public final class ArrayPtg extends Ptg { private static String getConstantText(Object o) { if (o == null) { - throw new RuntimeException("Array item cannot be null"); + throw new IllegalStateException("Array item cannot be null"); } if (o instanceof String) { return "\"" + o + "\""; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java index 5eeb7bbaaa..fb3aed7c91 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java @@ -54,7 +54,7 @@ public final class DeletedArea3DPtg extends OperandPtg implements WorkbookDepend return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, FormulaError.REF.getString()); } public String toFormulaString() { - throw new RuntimeException("3D references need a workbook to determine formula text"); + throw new IllegalStateException("3D references need a workbook to determine formula text"); } @Override public byte getDefaultOperandClass() { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java index eab861b34f..ed1d7b3f74 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java @@ -54,7 +54,7 @@ public final class DeletedRef3DPtg extends OperandPtg implements WorkbookDepende return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, FormulaError.REF.getString()); } public String toFormulaString() { - throw new RuntimeException("3D references need a workbook to determine formula text"); + throw new IllegalStateException("3D references need a workbook to determine formula text"); } @Override public byte getDefaultOperandClass() { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/ErrPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/ErrPtg.java index 6cb5d41803..43e0857a3b 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/ErrPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/ErrPtg.java @@ -92,7 +92,7 @@ public final class ErrPtg extends ScalarConstantPtg { case REF: return REF_INVALID; case VALUE: return VALUE_INVALID; default: - throw new RuntimeException("Unexpected error code (" + code + ")"); + throw new IllegalStateException("Unexpected error code (" + code + ")"); } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/ExpPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/ExpPtg.java index 6c125e652c..af6b2ed389 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/ExpPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/ExpPtg.java @@ -68,7 +68,7 @@ public final class ExpPtg extends ControlPtg { @Override public String toFormulaString() { - throw new RuntimeException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't"); + throw new IllegalStateException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't"); } @Override diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/FuncPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/FuncPtg.java index 9fbcc89690..a7492eb17a 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/FuncPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/FuncPtg.java @@ -38,7 +38,7 @@ public final class FuncPtg extends AbstractFunctionPtg { public static FuncPtg create(int functionIndex) { FunctionMetadata fm = FunctionMetadataRegistry.getFunctionByIndex(functionIndex); if(fm == null) { - throw new RuntimeException("Invalid built-in function index (" + functionIndex + ")"); + throw new IllegalStateException("Invalid built-in function index (" + functionIndex + ")"); } return new FuncPtg(functionIndex, fm); } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/NamePtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/NamePtg.java index af569e51f2..be047d8b05 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/NamePtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/NamePtg.java @@ -87,7 +87,7 @@ public final class NamePtg extends OperandPtg implements WorkbookDependentFormul @Override public String toFormulaString() { - throw new RuntimeException("3D references need a workbook to determine formula text"); + throw new IllegalStateException("3D references need a workbook to determine formula text"); } @Override diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/NameXPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/NameXPtg.java index 4429c2ee10..31d006bf2f 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/NameXPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/NameXPtg.java @@ -84,7 +84,7 @@ public final class NameXPtg extends OperandPtg implements WorkbookDependentFormu return book.resolveNameXText(this); } public String toFormulaString() { - throw new RuntimeException("3D references need a workbook to determine formula text"); + throw new IllegalStateException("3D references need a workbook to determine formula text"); } @Override diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java index 7096921c43..5362fcc2b6 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java @@ -94,7 +94,7 @@ public final class Ref3DPtg extends RefPtgBase implements WorkbookDependentFormu return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, formatReferenceAsString()); } public String toFormulaString() { - throw new RuntimeException("3D references need a workbook to determine formula text"); + throw new IllegalStateException("3D references need a workbook to determine formula text"); } @Override diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/TblPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/TblPtg.java index 63a2aa759e..6355251368 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/TblPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/TblPtg.java @@ -78,7 +78,7 @@ public final class TblPtg extends ControlPtg { public String toFormulaString() { // table(....)[][] - throw new RuntimeException("Table and Arrays are not yet supported"); + throw new IllegalStateException("Table and Arrays are not yet supported"); } @Override diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java index 52fc644525..e26dd43ace 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java @@ -54,6 +54,6 @@ public abstract class ValueOperatorPtg extends OperationPtg { @Override public final String toFormulaString() { // TODO - prune this method out of the hierarchy - throw new RuntimeException("toFormulaString(String[] operands) should be used for subclasses of OperationPtgs"); + throw new IllegalStateException("toFormulaString(String[] operands) should be used for subclasses of OperationPtgs"); } } diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java index 6b16d7e79b..e68e223b0c 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -1138,7 +1138,7 @@ public class DataFormatter { case ERROR: return FormulaError.forInt(cell.getErrorCellValue()).getString(); default: - throw new RuntimeException("Unexpected celltype (" + cellType + ")"); + throw new IllegalStateException("Unexpected celltype (" + cellType + ")"); } } diff --git a/poi/src/main/java/org/apache/poi/ss/util/AreaReference.java b/poi/src/main/java/org/apache/poi/ss/util/AreaReference.java index 6ccb17852a..fc45d81b4a 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/AreaReference.java +++ b/poi/src/main/java/org/apache/poi/ss/util/AreaReference.java @@ -70,7 +70,7 @@ public class AreaReference { String part1 = parts[1]; if (isPlainColumn(part0)) { if (!isPlainColumn(part1)) { - throw new RuntimeException("Bad area ref '" + reference + "'"); + throw new IllegalStateException("Bad area ref '" + reference + "'"); } // Special handling for whole-column references // Represented internally as x$1 to x$65536 @@ -301,7 +301,7 @@ public class AreaReference { // TODO - are references like "Sheet1!A1:Sheet1:B2" ever valid? // FormulaParser has code to handle that. - throw new RuntimeException("Unexpected " + SHEET_NAME_DELIMITER + throw new IllegalStateException("Unexpected " + SHEET_NAME_DELIMITER + " in second cell reference of '" + reference + "'"); } diff --git a/poi/src/main/java/org/apache/poi/ss/util/CellRangeAddressList.java b/poi/src/main/java/org/apache/poi/ss/util/CellRangeAddressList.java index d76f20660a..4aad2e784b 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/CellRangeAddressList.java +++ b/poi/src/main/java/org/apache/poi/ss/util/CellRangeAddressList.java @@ -93,10 +93,10 @@ public class CellRangeAddressList implements GenericRecord { } public CellRangeAddress remove(int rangeIndex) { if (_list.isEmpty()) { - throw new RuntimeException("List is empty"); + throw new IllegalStateException("List is empty"); } if (rangeIndex < 0 || rangeIndex >= _list.size()) { - throw new RuntimeException("Range index (" + rangeIndex + throw new IllegalStateException("Range index (" + rangeIndex + ") is outside allowable range (0.." + (_list.size()-1) + ")"); } return _list.remove(rangeIndex); diff --git a/poi/src/main/java/org/apache/poi/ss/util/CellRangeUtil.java b/poi/src/main/java/org/apache/poi/ss/util/CellRangeUtil.java index c3a7afa1e9..50bf7a4250 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/CellRangeUtil.java +++ b/poi/src/main/java/org/apache/poi/ss/util/CellRangeUtil.java @@ -164,7 +164,7 @@ public final class CellRangeUtil { // range2 encloses range1, so replace it with the enclosing one return new CellRangeAddress[] { range2 }; } - throw new RuntimeException("unexpected intersection result (" + x + ")"); + throw new IllegalStateException("unexpected intersection result (" + x + ")"); } private static CellRangeAddress[] toArray(List temp) { diff --git a/poi/src/main/java/org/apache/poi/ss/util/NumberToTextConverter.java b/poi/src/main/java/org/apache/poi/ss/util/NumberToTextConverter.java index a7cd5af456..25a3eb963c 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/NumberToTextConverter.java +++ b/poi/src/main/java/org/apache/poi/ss/util/NumberToTextConverter.java @@ -167,7 +167,7 @@ public final class NumberToTextConverter { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; - if (Math.abs(decExponent)>98) { + if (Math.abs(decExponent) > 98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry @@ -176,7 +176,7 @@ public final class NumberToTextConverter { } else { decimalDigits = rnd.getSignificantDecimalDigits(); } - int countSigDigits = countSignifantDigits(decimalDigits); + int countSigDigits = countSignificantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { @@ -236,12 +236,12 @@ public final class NumberToTextConverter { return nDigits > MAX_TEXT_LEN; } - private static int countSignifantDigits(String sb) { - int result=sb.length()-1; + private static int countSignificantDigits(String sb) { + int result = sb.length()-1; while(sb.charAt(result) == '0') { result--; - if(result < 0) { - throw new RuntimeException("No non-zero digits found"); + if (result < 0) { + throw new IllegalStateException("No non-zero digits found"); } } return result + 1; diff --git a/poi/src/main/java/org/apache/poi/util/HexRead.java b/poi/src/main/java/org/apache/poi/util/HexRead.java index c6a5fb4f73..0e7266c4b5 100644 --- a/poi/src/main/java/org/apache/poi/util/HexRead.java +++ b/poi/src/main/java/org/apache/poi/util/HexRead.java @@ -134,7 +134,7 @@ public class HexRead { try { return readData(new ByteArrayInputStream( data.getBytes(StringUtil.UTF8) ), -1); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java index 66fec9473c..7c8427bcfe 100644 --- a/poi/src/main/java/org/apache/poi/util/IOUtils.java +++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java @@ -429,7 +429,7 @@ public final class IOUtils { public static long copy(InputStream srcStream, File destFile) throws IOException { File destDirectory = destFile.getParentFile(); if (!(destDirectory.exists() || destDirectory.mkdirs())) { - throw new RuntimeException("Can't create destination directory: "+destDirectory); + throw new IllegalStateException("Can't create destination directory: "+destDirectory); } try (OutputStream destStream = new FileOutputStream(destFile)) { return IOUtils.copy(srcStream, destStream); diff --git a/poi/src/main/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java b/poi/src/main/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java index 446c644f75..63cb50699c 100644 --- a/poi/src/main/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java +++ b/poi/src/main/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java @@ -46,7 +46,7 @@ public final class LittleEndianByteArrayOutputStream extends OutputStream implem private void checkPosition(int i) { if (i > _endIndex - _writeIndex) { - throw new RuntimeException("Buffer overrun"); + throw new IllegalStateException("Buffer overrun"); } } diff --git a/poi/src/main/java/org/apache/poi/util/LittleEndianInputStream.java b/poi/src/main/java/org/apache/poi/util/LittleEndianInputStream.java index 459520cf55..e6d1a84cb7 100644 --- a/poi/src/main/java/org/apache/poi/util/LittleEndianInputStream.java +++ b/poi/src/main/java/org/apache/poi/util/LittleEndianInputStream.java @@ -46,7 +46,7 @@ public class LittleEndianInputStream extends FilterInputStream implements Little try { return super.available(); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -61,7 +61,7 @@ public class LittleEndianInputStream extends FilterInputStream implements Little try { checkEOF(read(buf), 1); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } return LittleEndian.getUByte(buf); } @@ -88,7 +88,7 @@ public class LittleEndianInputStream extends FilterInputStream implements Little try { checkEOF(read(buf), buf.length); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } return LittleEndian.getInt(buf); } @@ -112,7 +112,7 @@ public class LittleEndianInputStream extends FilterInputStream implements Little try { checkEOF(read(buf), LittleEndianConsts.LONG_SIZE); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } return LittleEndian.getLong(buf); } @@ -128,14 +128,14 @@ public class LittleEndianInputStream extends FilterInputStream implements Little try { checkEOF(read(buf), LittleEndianConsts.SHORT_SIZE); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } return LittleEndian.getUShort(buf); } private static void checkEOF(int actualBytes, int expectedBytes) { if (expectedBytes != 0 && (actualBytes == -1 || actualBytes != expectedBytes)) { - throw new RuntimeException("Unexpected end-of-file"); + throw new IllegalStateException("Unexpected end-of-file"); } } @@ -149,7 +149,7 @@ public class LittleEndianInputStream extends FilterInputStream implements Little try { checkEOF(_read(buf, off, len), len); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } diff --git a/poi/src/main/java/org/apache/poi/util/LittleEndianOutputStream.java b/poi/src/main/java/org/apache/poi/util/LittleEndianOutputStream.java index 156b2e2e82..e3a76cfbf6 100644 --- a/poi/src/main/java/org/apache/poi/util/LittleEndianOutputStream.java +++ b/poi/src/main/java/org/apache/poi/util/LittleEndianOutputStream.java @@ -31,7 +31,7 @@ public final class LittleEndianOutputStream extends FilterOutputStream implement try { out.write(v); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -52,7 +52,7 @@ public final class LittleEndianOutputStream extends FilterOutputStream implement out.write(b2); out.write(b3); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -70,7 +70,7 @@ public final class LittleEndianOutputStream extends FilterOutputStream implement out.write(b0); out.write(b1); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @Override @@ -79,7 +79,7 @@ public final class LittleEndianOutputStream extends FilterOutputStream implement try { super.write(b); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @Override @@ -88,7 +88,7 @@ public final class LittleEndianOutputStream extends FilterOutputStream implement try { super.write(b, off, len); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -106,7 +106,7 @@ public final class LittleEndianOutputStream extends FilterOutputStream implement out.write( (byte) ( ( value >>> 16 ) & 0xFF ) ); out.write( (byte) ( ( value >>> 24 ) & 0xFF ) ); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -121,7 +121,7 @@ public final class LittleEndianOutputStream extends FilterOutputStream implement out.write( (byte) ( ( value ) & 0xFF ) ); out.write( (byte) ( ( value >>> 8 ) & 0xFF ) ); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } } diff --git a/poi/src/main/java/org/apache/poi/util/XMLHelper.java b/poi/src/main/java/org/apache/poi/util/XMLHelper.java index a5ebc6db83..5eb218ecd4 100644 --- a/poi/src/main/java/org/apache/poi/util/XMLHelper.java +++ b/poi/src/main/java/org/apache/poi/util/XMLHelper.java @@ -166,7 +166,7 @@ public final class XMLHelper { throw re; } catch (Exception e) { logThrowable(e, "Failed to create SAXParserFactory", "-"); - throw new RuntimeException("Failed to create SAXParserFactory", e); + throw new IllegalStateException("Failed to create SAXParserFactory", e); } } -- 2.39.5