[jexl] - Lazy evaluation
udit gupta
2018-10-23 03:54:29 UTC

The use case is to lazily evaluate variables in expression, as they are

Jexl already supports boolean short circuiting. Expression = ((A || B) &&C)

if A = True, B doesn't have to be set during expression evaluation.

However if A = False and B is not set, the evaluation throws JexlException
exception - undefined variable B.

One approach I tried Is to catch JexlException and then proceeding to
evaluate missing variable.

private String getNextVariableToEvaluate(){

try { expression.evaluate(context);

} catch (JexlException.Variable jexl) {

return jexl.getVariable();


return null;


This works, but because of throwing Exceptions it can be costly as it
generates stack trace every time.

Is there a clean way to find out if the expression can be short circuited
with what variables value we know currently?

If not, which is the variable that should be evaluated?
Udit Kumar Gupta