vars.get() returns void in a java script if the variable is not existing instead of null (as described in it's documentation http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html#get%28java.lang.String%29 ) This will lead to confusion and bugs if the user doesn't know this.
(In reply to Bernhard from comment #0) > vars.get() returns void in a java script if the variable is not existing > instead of null (as described in it's documentation Are you sure? I cannot find any references that says that javascript can return void. > http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables. > html#get%28java.lang.String%29 ) That Javadoc is correct; Java returns null (and does not have a concept of void as a return type) > This will lead to confusion and bugs if the user doesn't know this. Possibly, but it's not clear that there is a problem here. Please provide sample code that exhibits the problem.
Created attachment 31880 [details] testplan with bug Sorry for the confusion, I meant java, not javascript. I'll add a test plan to make it clear what's wrong. In the test plan there is a JSR223 with Java which tries to get a nonexistent variable out of vars. Then there are 2 ifs which compare the nonexistent variable with null and void and log and add "null" or "void" to the ResponseMessage.
Thanks for the sample JMX. The code is not Java either - it is BeanShell. Java does not support void as a value, only as a return type qualifier. Whereas BeanShell uses void to indicate a non-existent variable. == It's not yet clear why assigning null to the variable o should result in it being void rather than null as expected. It looks to be a side effect of using the JSR223 sampler rather than the BeanShell sampler, as the same code works as expected in the BeanShell sampler, and also works as expected in a Beanshell interpreter or console app. It remains to be seen whether this is a feature or bug in the JSR223 BeanShell support in JMeter or in BeanShell. Meanwhile the workround is to use the BeanShell test elements to run BeanShell code.
In the latest trunk 3.2-SNAPSHOT all of the following match x == void but do NOT match x == null in the JSR223 sampler: var x; var x = null; Object x = null; String x = null; Not sure if it's a bug, but it looks like expected BeanShell behaviour looking at the BeanShell docs (http://www.beanshell.org/manual/bshmanual.html): unset void unset ( String name ) "Undefine" the variable specifed by 'name' (So that it tests == void). Note: there will be a better way to do this in the future. This is currently equivalent to doing namespace.setVariable(name, null); Maybe we should document this in our JSR223 sampler as this is different to the BeanShell sampler which seems to display the opposite behaviour i.e. all the above tests only match == null not == void - this looks more like a bug to me, but is perhaps less intuitive when mixed with Java code.
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/3411