jmeterjmeter-4.0jexl

JMeter - jexl3 function can't declare local variables


I'm using latest JMeter 4 and trying to use basic jexl syntax of declaring local variable in jexl function

Local variables Can be defined using the var keyword; their identifying rules are the same as contextual variables. Basic declaration: var x;

So in JMeter I tried

${__jexl2(var x;)}

and succeeded, but using ${__jexl3(var x;)} it throw an parser exception:

2018-04-25 14:18:16,451 ERROR o.a.j.f.Jexl3Function: An error occurred while evaluating the expression "var a;"

org.apache.commons.jexl3.JexlException$Parsing: @1:1 parsing error in 'var'
    at org.apache.commons.jexl3.JexlEngine.createExpression(JexlEngine.java:304) ~[commons-jexl3-3.1.jar:3.1]
    at org.apache.jmeter.functions.Jexl3Function.execute(Jexl3Function.java:94) [ApacheJMeter_functions.jar:4.0 r1823414]
    at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:137) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:112) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:101) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:281) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.testelement.AbstractTestElement.getName(AbstractTestElement.java:165) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.sampler.DebugSampler.sample(DebugSampler.java:56) [ApacheJMeter_components.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:490) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:416) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:250) [ApacheJMeter_core.jar:4.0 r1823414]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]

Is it a JMeter issue or jexl3 issue, or am I missing something?

EDIT

In addition to failure to parse var, it can't parse ;, here's a working example with jexl2 that failed with jexl3:

${__jexl3(abc=new("java.util.ArrayList"\, 1);)}

Solution

  • It was a bug in JMeter Jexl3 implementation according to jexl issue:

    JMeter using JexlExpression instead of JexlScript

    Bug is fixed now and will be uploaded next version