1

How to get all warning message of unknown variables?

I have a expression which I would like to evaluate and know all the missing variables.

Example:

jexl.setStrict(false);
Expression e = (Expression) jexl.createExpression("(pqr||abc)&&xyx&&!(rsw||ruy)&&!sss");

JexlContext context = new MapContext();
 context.set("rsw",false);  
 context.set("xyx",true);   
 Object obj=e.evaluate(context);
 System.out.println(obj);

Output:

Aug 11, 2017 10:58:24 AM org.apache.commons.jexl2.Interpreter unknownVariable
WARNING: com.AdhocPrograms.JexlExample.main@40![1,4]: '(pqr || abc) && xyx && !(rsw || ruy) && !sss;' undefined variable pqr
false
Aug 11, 2017 10:58:24 AM org.apache.commons.jexl2.Interpreter unknownVariable
WARNING: com.AdhocPrograms.JexlExample.main@40![8,11]: '(pqr || abc) && xyx && !(rsw || ruy) && !sss;' undefined variable abc

I would like to capture both of the undefined variables. If I set jexl.setStrict(true) and add try and catch block, I can capture only one variable.

  catch(JexlException.Variable xjexl)       {
            System.out.println("Exception:" +xjexl.getVariable());          
            xjexl.printStackTrace();
        }

I am open to use another technology as well.

James Z
  • 12,209
  • 10
  • 24
  • 44
Uma
  • 21
  • 8

1 Answers1

1

I was able to work around with below getVariables() method.

Sample:

jexl.createScript("(pqr||abc)&&xyx&&!(rsw||ruy)&&!sss").getVariables();

Uma
  • 21
  • 8
  • Do you know how works getParameters instead? I get always a null pointer at sentence. I want to get all parameters including constants, It is possible? – Osy Apr 11 '18 at 19:21