From 98fbe88d3a7edde2da4bc3694788f3fdfb57fe5b Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 20 Mar 2022 06:52:59 +0000 Subject: [PATCH] Improve error message if formula cannot be parsed git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899075 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/ss/formula/FormulaParser.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 47a4b33404..00cd8fa1e6 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 @@ -97,6 +97,7 @@ import org.apache.poi.util.Internal; @Internal public final class FormulaParser { private static final Logger LOGGER = LogManager.getLogger(FormulaParser.class); + private final String _formulaString; private final int _formulaLength; /** points at the next character to be read (after the {@link #look} codepoint) */ @@ -681,11 +682,10 @@ public final class FormulaParser { GetChar(); } // parse column quantifier - String startColumnName; String endColumnName = null; int nColQuantifiers = 0; int savePtr1 = _pointer; - startColumnName = parseAsColumnQuantifier(); + String startColumnName = parseAsColumnQuantifier(); if (startColumnName == null) { resetPointer(savePtr1); } else { @@ -799,7 +799,7 @@ public final class FormulaParser { if (nColQuantifiers == 2) { if (startColumnName == null || endColumnName == null) { - throw new IllegalStateException("Fatal error"); + throw new IllegalStateException("Cannot parse column: " + startColumnName + " and " + endColumnName + " with formula " + _formulaString); } int startIdx = tbl.findColumnIndex(startColumnName); int endIdx = tbl.findColumnIndex(endColumnName); @@ -811,7 +811,7 @@ public final class FormulaParser { } else if (nColQuantifiers == 1 && !isThisRow) { if (startColumnName == null) { - throw new IllegalStateException("Fatal error"); + throw new IllegalStateException("Cannot parse column: " + startColumnName + " with formula " + _formulaString); } int idx = tbl.findColumnIndex(startColumnName); if (idx == -1) {