From: Dominik Stadler Date: Mon, 30 Dec 2019 19:57:11 +0000 (+0000) Subject: Fix bug 63984: AND / OR should treat missing parameters as FALSE X-Git-Tag: REL_4_1_2~62 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc0dcdf36929e2b5c8761faa9c5c5cf29be3f367;p=poi.git Fix bug 63984: AND / OR should treat missing parameters as FALSE git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872125 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/ss/formula/functions/BooleanFunction.java b/src/java/org/apache/poi/ss/formula/functions/BooleanFunction.java index 5b5b539fef..5177b851a6 100644 --- a/src/java/org/apache/poi/ss/formula/functions/BooleanFunction.java +++ b/src/java/org/apache/poi/ss/formula/functions/BooleanFunction.java @@ -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(); } diff --git a/test-data/spreadsheet/BooleanFunctionsTestCaseData.xls b/test-data/spreadsheet/BooleanFunctionsTestCaseData.xls index 74798eb567..44808a5112 100644 Binary files a/test-data/spreadsheet/BooleanFunctionsTestCaseData.xls and b/test-data/spreadsheet/BooleanFunctionsTestCaseData.xls differ