Vincent Bussol created JEXL-435:
-----------------------------------
Summary: Changed behavior of empty operator overloading
Key: JEXL-435
URL: https://issues.apache.org/jira/browse/JEXL-435
Project: Commons JEXL
Issue Type: Bug
Affects Versions: 3.4.1
Reporter: Vincent Bussol
In the previous versions (since
[3.2|https://github.com/apache/commons-jexl/commit/7f1336e81d1b84ffe53d53a408380e5cfd94d91c]),
it was possible to overload the empty operator and return an object that was
not a boolean.
The java documentation still mentions:
{code:java}
Note that the result may not be a boolean. {code}
The current version returns true if the returned object is not a boolean.
{code:java}
public static class OverloadedArithmetic extends JexlArithmetic {
public OverloadedArithmetic(boolean strict) {
super(strict);
}
public Object empty(String type) {
if ("list".equals(type)) {
return Collections.emptyList();
}
return null;
}
}
@Test
void test() {
JexlArithmetic arithmetic = new OverloadedArithmetic(true);
JexlEngine jexl = new JexlBuilder().arithmetic(arithmetic).create();
final String src = "empty('list')";
final JexlScript script = jexl.createScript(src);
assertNotNull(script);
final Object result = script.execute(null);
assertTrue(result instanceof List);
}{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)