Abhishek Asthana Abhishek Asthana - 5 months ago 29
Groovy Question

Groovy using a different value from what was initialized

In my JMeter script i have defined a User Defined Variable i whose value is set to 1. Then i created a JSR22 pre-processor for my HTTP sample that just increments the value of i using the below code.


Integer intI = vars.get("i");

intI = intI + 1;

vars.put("i", intI.toString());


The problem seems to be that instead of picking up 1 as the initial value of i it is picking 49 and increment it to 50.

I was able to fix it by changing

Integer intId = vars.get("id")


Integer intId = vars.get("id").toInteger();

But i am curious to know what could be causing this.


As requested, the conclusion from the comments as answer:

vars.get() returns a String which, when assigned to an Integer gets implicitly converted to the corresponding ASCII value.

This can be observed in the snippet: def v = "1"; Integer intId = v; println intId -> prints 49