title: jmeter Beanshell - Error invoking bsh method: eval
body: <p>I am trying to print 3 variables from 3 different HTTP requests in same Thread Group .
  I wrote following BeanShell in Jmeter:</p>
  
  <pre><code>try {
      hash1 = vars.get("var_Hash_1");
      hash2 = vars.get("var_Hash_2");
      hash3 = vars.get("var_Hash_3");
      FileWriter fstream = new FileWriter("/tmp/result.txt",true);
      BufferedWriter out = new BufferedWriter(fstream);
      out.write(hash1);
      out.write(",");
      out.write(hash2);
      out.write(",");
      out.write(hash3);
      out.write(",");
      out.write("\n");
      out.close();
      fstream.close();
  }
  catch (Throwable e) {
      log.error("Errror in Beanshell", e);
      throw e;
  }
  </code></pre>
  
  <p>And the exception is:</p>
  
  <blockquote>
    <p>2017/04/26 16:16:25 WARN  - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval
           Sourced file: inline evaluation of: ``try { hash1 = vars.get("var_Hash_1"); hash2 = vars.get("var_Hash_2"); hash3 = va . . . '' : TargetError</p>
  </blockquote>
  
  <p>Whats intersting is that if I try to write only hash1 and hash2 same exception occurs but there is something written out to a result.txt file (hash1,hash2)
  with hash1,hash2,hash3 nothing is written out.</p>
  
  <p>All 3 variables shall exists as I execute 3 similar request and they are successfull. Any ideas?</p>
  
  <p>Edited: Log file from exception:</p>
  
  <pre><code>2017/04/26 17:30:29 ERROR - jmeter.util.BeanShellTestElement: Errror in Beanshell java.lang.NullPointerException
          at java.io.Writer.write(Writer.java:127)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:483)
          at bsh.Reflect.invokeMethod(Reflect.java:134)
          at bsh.Reflect.invokeObjectMethod(Reflect.java:80)
          at bsh.Name.invokeMethod(Name.java:858)
          at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
          at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
          at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
          at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
          at bsh.BSHBlock.eval(BSHBlock.java:80)
          at bsh.BSHBlock.eval(BSHBlock.java:46)
          at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
          at bsh.Interpreter.eval(Interpreter.java:645)
          at bsh.Interpreter.eval(Interpreter.java:739)
          at bsh.Interpreter.eval(Interpreter.java:728)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:483)
          at org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:170)
          at org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:197)
          at org.apache.jmeter.util.BeanShellTestElement.processFileOrScript(BeanShellTestElement.java:151)
          at org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:64)
          at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:750)
          at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:452)
          at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
          at java.lang.Thread.run(Thread.java:745)
  </code></pre>