From bc0dcdf36929e2b5c8761faa9c5c5cf29be3f367 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 30 Dec 2019 19:57:11 +0000 Subject: [PATCH] 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 --- .../ss/formula/functions/BooleanFunction.java | 22 +++++++++--------- .../BooleanFunctionsTestCaseData.xls | Bin 28160 -> 30208 bytes 2 files changed, 11 insertions(+), 11 deletions(-) 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 74798eb56733b04f4ca14f5c6a989db9de70256a..44808a5112157166b966133bb171cc038d0fa487 100644 GIT binary patch literal 30208 zcmeHQ32+vBv*+JSE6IbmPY}}g@_0Q7#x!2 zTD9CJolfnhiR{{wSj}lS@e${8>a=?3M=kX`w}$TyO)|H#+$? z!TmykS?6~Lt^uka|A#El5`iO|8fA3Hmzw|Tq9IMqBHxsdd?Nf3&LaPabWEmYuE=yO zmr0DD>={d2C#?)G&Huh*Sm_Wmr~}lJT}BuY8IlV~?XpzqHcy@BtMkVd=I7LTm&}tp zrBznH`NNxc2&2}JJ3@mB?|0QXs?Kw9Hsl3G^QwYukyUaT_z`&*$soMh7?GGHB_U&y z!TEm@!+;*2qXB*{JzB0&7DEOcDMoN<4cY2o%nQa4+3iTFfZ-}j1&oj^c6d~@db@*B zfrrS=*Th&*6=TvcWQV7;Q?~D8%KO~`80GO1z9z(qBpFaX3Mf&<%c(rTfI<{gS})dycpV;L6=W;=JalBsLhYT>Joi zmjWEyu+s)aH$|cM@vgz+kkTVhA&NlirrT(`i8h*L6a(_K+*B@1m!MppQq3iDV4x&) zn>>Sduq4!>FUoa@m1sBRLU~p&+K9f{%0_qE=R@h}s_-)T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