From 0bb651955eb1afc749d0e52079baf44e3ce9781a Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 5 Sep 2021 19:05:54 +0000 Subject: [PATCH] more specific exception instead of NPE git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892951 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/formula/OperationEvaluationContext.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 9b6cda50c5..60fc0145e7 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 @@ -210,7 +210,6 @@ public final class OperationEvaluationContext { } SheetRangeEvaluator sre = new SheetRangeEvaluator(_sheetIndex, se); - // ugly typecast - TODO - make spreadsheet version more easily accessible SpreadsheetVersion ssVersion = _workbook.getSpreadsheetVersion(); NameType part1refType = classifyCellReference(refStrPart1, ssVersion); @@ -219,7 +218,11 @@ public final class OperationEvaluationContext { return ErrorEval.REF_INVALID; case NAMED_RANGE: EvaluationName nm = _workbook.getName(refStrPart1, _sheetIndex); - if(!nm.isRange()){ + if(nm == null) { + throw new RuntimeException("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."); } return _bookEvaluator.evaluateNameFormula(nm.getNameDefinition(), this); -- 2.39.5