aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-02-25 18:25:35 +0000
committerPJ Fanning <fanningpj@apache.org>2022-02-25 18:25:35 +0000
commit18a5720eeb2aa255a993497aceca6c2343876aeb (patch)
tree9a2690cc143e53ba90a16861447a3beee92c6b9b /poi
parentba252f20b5aa30d5a992d79a8fd0932a5086a981 (diff)
downloadpoi-18a5720eeb2aa255a993497aceca6c2343876aeb.tar.gz
poi-18a5720eeb2aa255a993497aceca6c2343876aeb.zip
[bug-65915] possible issue in boolean function support
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898421 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/functions/BooleanFunction.java11
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/functions/TestOrFunction.java16
2 files changed, 23 insertions, 4 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/BooleanFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/BooleanFunction.java
index d051dacc12..50034f6dec 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/BooleanFunction.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/BooleanFunction.java
@@ -139,11 +139,14 @@ public abstract class BooleanFunction implements Function,ArrayFunction {
@Override
public ValueEval evaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
- if (args.length != 1) {
- return ErrorEval.VALUE_INVALID;
+ if (args.length == 1) {
+ return evaluateOneArrayArg(args[0], srcRowIndex, srcColumnIndex,
+ vA -> evaluate(new ValueEval[]{vA}, srcRowIndex, srcColumnIndex));
+ } else if (args.length == 2) {
+ return evaluateTwoArrayArgs(args[0], args[1], srcRowIndex, srcColumnIndex,
+ (vA, vB) -> evaluate(new ValueEval[]{vA, vB}, srcRowIndex, srcColumnIndex));
}
- return evaluateOneArrayArg(args[0], srcRowIndex, srcColumnIndex,
- vA -> evaluate(new ValueEval[]{vA}, srcRowIndex, srcColumnIndex));
+ return ErrorEval.VALUE_INVALID;
}
private static ValueEval evaluateFalse(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOrFunction.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOrFunction.java
index 6a972e3719..83252ac5c1 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOrFunction.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestOrFunction.java
@@ -23,6 +23,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.util.CellRangeAddress;
import org.junit.jupiter.api.Test;
import java.io.IOException;
@@ -31,6 +32,7 @@ import static org.apache.poi.ss.util.Utils.addRow;
import static org.apache.poi.ss.util.Utils.assertBoolean;
import static org.apache.poi.ss.util.Utils.assertDouble;
import static org.apache.poi.ss.util.Utils.assertString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests for {@link BooleanFunction#OR}
@@ -88,6 +90,20 @@ final class TestOrFunction {
}
}
+ @Test
+ void testBug65915ArrayFunction() throws IOException {
+ //https://bz.apache.org/bugzilla/show_bug.cgi?id=65915
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ HSSFSheet sheet = wb.createSheet();
+ HSSFRow row = sheet.createRow(0);
+ HSSFCell cell = row.createCell(0);
+ sheet.setArrayFormula("INDEX({1},1,IF(OR(FALSE,FALSE),1,1))", new CellRangeAddress(0, 0, 0, 0));
+ fe.evaluateAll();
+ assertEquals(1.0, cell.getNumericCellValue());
+ }
+ }
+
private HSSFWorkbook initWorkbook1() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();