aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-02-07 20:55:26 +0000
committerPJ Fanning <fanningpj@apache.org>2022-02-07 20:55:26 +0000
commit3feb4ac6cfad722df03b6761ed49bbd3f72116dc (patch)
treee07a76a32815bf4ce49ec1e97e6ddfabefa72195 /poi
parent7702246209e72255febfe5b800fc925291b8767a (diff)
downloadpoi-3feb4ac6cfad722df03b6761ed49bbd3f72116dc.tar.gz
poi-3feb4ac6cfad722df03b6761ed49bbd3f72116dc.zip
add negative tets
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897827 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/OperationEvaluationContext.java2
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/functions/Indirect.java10
-rw-r--r--poi/src/main/java/org/apache/poi/ss/util/CellReference.java1
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndirect.java1
4 files changed, 13 insertions, 1 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 4050d7b11f..5b4799f35a 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
@@ -207,6 +207,8 @@ public final class OperationEvaluationContext {
* @param isA1Style specifies the format for {@code refStrPart1} and {@code refStrPart2}.
* Pass {@code true} for 'A1' style and {@code false} for 'R1C1' style.
* @return a {@link RefEval} or {@link AreaEval}
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
*/
public ValueEval getDynamicReference(String workbookName, String sheetName, String refStrPart1,
String refStrPart2, boolean isA1Style) {
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Indirect.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Indirect.java
index 90b581d765..9cf3ade073 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Indirect.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Indirect.java
@@ -17,6 +17,8 @@
package org.apache.poi.ss.formula.functions;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.formula.FormulaParser;
import org.apache.poi.ss.formula.FormulaParsingWorkbook;
@@ -45,6 +47,7 @@ import org.apache.poi.ss.usermodel.Table;
*/
public final class Indirect implements FreeRefFunction {
+ private static final Logger LOGGER = LogManager.getLogger(Indirect.class);
public static final FreeRefFunction instance = new Indirect();
private Indirect() {
@@ -136,7 +139,12 @@ public final class Indirect implements FreeRefFunction {
refStrPart1 = refText.substring(0, colonPos).trim();
refStrPart2 = refText.substring(colonPos + 1).trim();
}
- return ec.getDynamicReference(workbookName, sheetName, refStrPart1, refStrPart2, isA1style);
+ try {
+ return ec.getDynamicReference(workbookName, sheetName, refStrPart1, refStrPart2, isA1style);
+ } catch (Exception e) {
+ LOGGER.atWarn().log("Indirect function: failed to parse reference {}", text, e);
+ return ErrorEval.REF_INVALID;
+ }
}
}
diff --git a/poi/src/main/java/org/apache/poi/ss/util/CellReference.java b/poi/src/main/java/org/apache/poi/ss/util/CellReference.java
index 6e2412f9e2..0e8ea7dee4 100644
--- a/poi/src/main/java/org/apache/poi/ss/util/CellReference.java
+++ b/poi/src/main/java/org/apache/poi/ss/util/CellReference.java
@@ -109,6 +109,7 @@ public class CellReference implements GenericRecord {
/**
* Create an cell ref from a string representation. Sheet names containing special characters should be
* delimited and escaped as per normal syntax rules for formulas.
+ * @throws IllegalArgumentException if cellRef is not valid
*/
public CellReference(String cellRef) {
if(endsWithIgnoreCase(cellRef, "#REF!")) {
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndirect.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndirect.java
index 7a4ec7f270..6e670ec52f 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndirect.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndirect.java
@@ -177,6 +177,7 @@ final class TestIndirect {
// simple error propagation:
confirm(feA, c, "INDIRECT(\"'Sheet1 '!R3C4\", FALSE)", ErrorEval.REF_INVALID);
+ confirm(feA, c, "INDIRECT(\"R2CX\", FALSE)", ErrorEval.REF_INVALID);
}
}