[jexl] - Lazy evaluation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

[jexl] - Lazy evaluation

udit gupta

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
Reply | Threaded
Open this post in threaded view

Re: [jexl] - Lazy evaluation


You can implement your own JexlContext (and wrap/delegate to any existing
one); the 'has' method determines whether a variable exists and the 'get'
method, its actual value.
There are many examples in the tests (JexlEvalContext for instance).

Sent from: http://apache-commons.680414.n4.nabble.com/Commons-User-f735979.html

To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]