title: I am unable to transfer values between samplers using JavaSamplerContext.getJMeterVariables() in jmeter java
body: <p>I am relatively new to Jmeter so please bearvwith me :) According to the <a href="https://jmeter.apache.org/api/org/apache/jmeter/protocol/java/sampler/JavaSamplerContext.html#getJMeterVariables--" rel="nofollow noreferrer">documentation</a>, <em><strong>getJMeterVariables</strong></em> returns the jmeter variables for the current thread which I believed was instantiated when I created the <em><strong>JavaSamplerContext</strong></em>. However, it seems like its not the case as <em><strong>JavaSamplerContext.getJMeterVariables</strong></em> is null and when I try to add values to it:</p>
  <pre><code> JavaSamplerContext.getJMeterVariables().put(&quot;something&quot;,&quot;something&quot;);
  </code></pre>
  <p>I get null pointer exception. My goal is to debug how values pass between samplers and my scenario is something like the following - a main class that calls the different samplers and looks like:</p>
  <pre><code> public static void main(String[] args) {
  
          Sampler1 sampler1 = new Sampler1();
          Sampler2 sampler2 = new Sampler2();
          JavaSamplerContext context = new JavaSamplerContext(getArguments());
  
          Sampler1.runTest(context);
          Sampler2.runTest(context);
  
  }
  </code></pre>
  <p>I would like to use JavaSamplerContext.getJMeterVariables().put(&quot;something&quot;,&quot;something&quot;) to transfer values between sampler1 and sampler2 and hence Sampler1 for example looks like:</p>
  <pre><code>public class Sampler1 extends AbstractJavaSamplerClient {
  
  
      @Override
      public SampleResult runTest(JavaSamplerContext context) {
  
      SampleResult result = new SampleResult();
  
      result.sampleStart();
      Something1 something1 = doSomething();
      String something2 = doSomething2()
      result.sampleEnd();
  
      context.getJMeterVariables().putObject(&quot;something1Key&quot;,Something1);
      context.getJMeterVariables().put(&quot;something2Key&quot;,something2);
      return result;
  }
  </code></pre>
  <p>While sampler2 will have: (<strong>Note that I am trying to transfer both String and an Object</strong>)</p>
  <pre><code>public class Sampler2 extends AbstractJavaSamplerClient {
  
  @Override
  public SampleResult runTest(JavaSamplerContext context) {
  
  String something2 = context.getJMeterVariables().get(&quot;something2Key&quot;);
  Something1 something1 = (Something1) context.getJMeterVariables().getObject(&quot;something1Key&quot;);
  ...
  }
  </code></pre>
  <p>What am I missing?</p>