Hussachai Puripunpinyo created JEXL-384:
-------------------------------------------
Summary: Revert null + String behavior
Key: JEXL-384
URL: https://issues.apache.org/jira/browse/JEXL-384
Project: Commons JEXL
Issue Type: Task
Affects Versions: 3.3
Reporter: Hussachai Puripunpinyo
https://issues.apache.org/jira/browse/JEXL-359
{quote}A typical case is '+' for string and null where one would like to
consider null as a valid argument even if arithmetic is strict.
{quote}
While the above reason is valid, the code introduced in JEXL-359 causes more
confusion, and the behavior is now inconsistent.
Also, I'd like to give some counter arguments about not supporting null +
string in the strict mode. If we want to make null + string works even if
arithmetic is strict, there will be no difference between "" + "ABC" and null +
"ABC" because both cases yield "ABC" in both strict and non-strict mode. In our
code base, we set the engine to be strict, so users have to be careful about
null since it can give an undesirable result. In a non-strict mode, we don't
have a way to distinguish whether the result is the combination of null or
empty string and a string. Users need to explicitly check for null, but there
will be no enforcement
which means nobody will do that check. That's why we prefer it to be strict and
a user has to check null before using or use some namespace functions that we
provide where null will be explicitly handled. Otherwise, the exception will be
thrown.
Let me elaborate why some part of JEXL-359 causes the behavior to be
inconsistent.
*Strict Mode*
{code:java}
var i = null;
i + 'ABC'; // This will throw an exception.
null + 'ABC'; // This yields 'ABC' - the same as non-strict mode.
{code}
*Non Strict Mode*
{code:java}
var i = null;
i + 'ABC'; // This yields 'ABC';
null + 'ABC'; // This also yields 'ABC';
{code}
You can see that the behavior of null + 'ABC' in the strict mode is not
consistent with the null variable.
Also, there is a way to allow string concatenation with null using a namespace
function in a strict mode, and I think JEXL shouldn't make an exception for
this one particular case.
I'd like to propose the PR with some regression tests that applies to only null
(literal) + string case.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)