Bug 56816 - Assigning null to a BeanShell variable in a JSR223 sampler does not work as expected
Summary: Assigning null to a BeanShell variable in a JSR223 sampler does not work as e...
Status: NEW
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 2.11
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-05 09:21 UTC by Bernhard
Modified: 2017-01-27 09:42 UTC (History)
1 user (show)



Attachments
testplan with bug (4.02 KB, text/plain)
2014-08-06 05:54 UTC, Bernhard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard 2014-08-05 09:21:41 UTC
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.
Comment 1 Sebb 2014-08-05 15:43:24 UTC
(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.
Comment 2 Bernhard 2014-08-06 05:54:11 UTC
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.
Comment 3 Sebb 2014-08-06 14:33:42 UTC
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.
Comment 4 Graham Russell 2017-01-27 09:42:22 UTC
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.