]> source.dussan.org Git - poi.git/commitdiff
Fix bug 63984: AND / OR should treat missing parameters as FALSE
authorDominik Stadler <centic@apache.org>
Mon, 30 Dec 2019 19:57:11 +0000 (19:57 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 30 Dec 2019 19:57:11 +0000 (19:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872125 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/functions/BooleanFunction.java
test-data/spreadsheet/BooleanFunctionsTestCaseData.xls

index 5b5b539feffc423126927e159ad4872f72ef4df9..5177b851a6471daf3c191bef11cc27c1105b127a 100644 (file)
@@ -55,7 +55,7 @@ public abstract class BooleanFunction implements Function,ArrayFunction {
        private boolean calculate(ValueEval[] args) throws EvaluationException {
 
                boolean result = getInitialResultValue();
-               boolean atleastOneNonBlank = false;
+               boolean atLeastOneNonBlank = false;
 
                /*
                 * Note: no short-circuit boolean loop exit because any ErrorEvals will override the result
@@ -71,8 +71,8 @@ public abstract class BooleanFunction implements Function,ArrayFunction {
                                                ValueEval ve = ae.getValue(rrIx, rcIx);
                                                tempVe = OperandResolver.coerceValueToBoolean(ve, true);
                                                if (tempVe != null) {
-                                                       result = partialEvaluate(result, tempVe.booleanValue());
-                                                       atleastOneNonBlank = true;
+                                                       result = partialEvaluate(result, tempVe);
+                                                       atLeastOneNonBlank = true;
                                                }
                                        }
                                }
@@ -86,26 +86,26 @@ public abstract class BooleanFunction implements Function,ArrayFunction {
                     ValueEval ve = re.getInnerValueEval(sIx);
                     tempVe = OperandResolver.coerceValueToBoolean(ve, true);
                     if (tempVe != null) {
-                        result = partialEvaluate(result, tempVe.booleanValue());
-                        atleastOneNonBlank = true;
+                        result = partialEvaluate(result, tempVe);
+                        atLeastOneNonBlank = true;
                     }
                 }
                 continue;
             }
-                       
+
                        if (arg == MissingArgEval.instance) {
-                               tempVe = null;          // you can leave out parameters, they are simply ignored
+                               tempVe = false;         // missing parameters are treated as FALSE
                        } else {
                                tempVe = OperandResolver.coerceValueToBoolean(arg, false);
                        }
 
                        if (tempVe != null) {
-                               result = partialEvaluate(result, tempVe.booleanValue());
-                               atleastOneNonBlank = true;
+                               result = partialEvaluate(result, tempVe);
+                               atLeastOneNonBlank = true;
                        }
                }
 
-               if (!atleastOneNonBlank) {
+               if (!atLeastOneNonBlank) {
                        throw new EvaluationException(ErrorEval.VALUE_INVALID);
                }
                return result;
@@ -161,7 +161,7 @@ public abstract class BooleanFunction implements Function,ArrayFunction {
                        try {
                                ValueEval ve = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
                                Boolean b = OperandResolver.coerceValueToBoolean(ve, false);
-                               boolArgVal = b == null ? false : b.booleanValue();
+                               boolArgVal = b == null ? false : b;
                        } catch (EvaluationException e) {
                                return e.getErrorEval();
                        }
index 74798eb56733b04f4ca14f5c6a989db9de70256a..44808a5112157166b966133bb171cc038d0fa487 100644 (file)
Binary files a/test-data/spreadsheet/BooleanFunctionsTestCaseData.xls and b/test-data/spreadsheet/BooleanFunctionsTestCaseData.xls differ