0

Jexl already supports boolean short circuiting Expression = A || B if A = True, B doesn't have to be set.

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

The use case is to lazily evaluate B. Is there a clean way to find out if the expression can be short circuited with what variables value we know currently? Is handling JexlException and then proceeding to evaluate B right way?

  • private String getNextVariableToEvaluate(){ try { expression.evaluate(context); } catch (JexlException.Variable jexl) { return jexl.getVariable(); } return null; } Intiatially if expression is {A || B && C} and we have A as true, the above will return C. However, if A is False, this will return B and we will then evaluate B. SO, I am trying to use the evaluate method [which has short-circuit], to find out which variable to evaluate lazily. But this has a cost due to exception stack trace. – user2401812 Oct 23 '18 at 03:12
  • Is there another clean way to get the next variable to lazily evaluate without the costly exceptions? – user2401812 Oct 23 '18 at 03:19
  • I don't understand the question enough to provide an answer, but I suspect your "context" just MapContext and you don't want to populate it with more variables than you need to evaluate expression. JexlExpression.evaluate() accepts a JexlContext so you could implement your own JexlContext to lazily provide (and cache) variables in the "get" and "has" methods. – David Costanzo Jun 08 '21 at 15:46

0 Answers0