title: My custom JMeter listener cannot work in Linux
body: <p>I want to save the information about sampleResult into MySQL. So I write my own listener named Performance Logger. And it can work well on my Windows. But when I move the same JMeter Script into Linux, it failed. Here are some code about my custom listener.</p>
  
  <pre><code>LoggerVisualizer.class
  
  public class LoggerVisualizer extends AbstractVisualizer {
  private PerformanceResultCollector collector;
  public LoggerVisualizer() {
      super();
      initConfiguration();
  }
  private void initConfiguration() {
      // some code
  }
  @Override
  public void clearData() {
      //some codes
  
  }
  public String getStaticLabel() {
      return "Performance Logger";
  }
  
  public String getLabelResource(){
      return "Performance Logger";
  }
  
  @Override
  public void add(SampleResult sampleResult) {
  
  }
  
  public TestElement createTestElement() {
      if (collector == null) {
          collector = new PerformanceResultCollector();
      }
      modifyTestElement(collector);
      return collector;
  }
  }
  </code></pre>
  
  <p>PerformanceResultCollector.class</p>
  
  <pre><code>public class PerformanceResultCollector extends ResultCollector implements Serializable {    
  CustomCollector collector;
  
  public PerformanceResultCollector() {    
      log.info("construct performance collector")
      collector = new CustomCollector();
  
  }
  @Override
  public void sampleOccurred(SampleEvent e) {
      collector.addSample(e.getResult());
  }
  
  public void cleanUp(){
      CustomCollector.cleanUp();
  }
  }
  </code></pre>
  
  <p>On my Windows server, I add the listener and it works well. I can see the data in the MySQL server. But when I move the script into the Linux and run it with command</p>
  
  <pre><code>  nohup ./jmeter -n -t /opt/tests/test.jmx -l /opt/log/perf_result.csv -Jjmeter.save.saveservice.output_format=csv -Jjmeter.save.saveservice.hostname=true -Jjmeter.save.saveservice.print_field_names=false -Jjmeter.save.saveservice.url=true -Jjmeter.save.saveservice.thread_counts=true -Jjmeter.save.saveservice.timestamp_format="yyyy-MM-dd HH:mm:ss" &gt; /opt/log/jmeter_script_run.out 2&gt; /opt/log/jmeter_script_run.err &lt; /dev/null
  </code></pre>
  
  <p>And I get the error in jmeter.log like:</p>
  
  <pre><code>2015/08/08 04:36:28 INFO  - com.test.jmeter.logger.PerformanceResultCollector: construct performance collector
  2015/08/08 04:36:28 ERROR - jmeter.save.SaveService: Conversion error com.thoughtworks.xstream.converters.ConversionException: java.lang.NullPointerException : java.lang.NullPointerException
  ---- Debugging information ----
  message             : java.lang.NullPointerException
  cause-exception     : java.lang.RuntimeException
  cause-message       : java.lang.NullPointerException
  class               : com.test.jmeter.logger.PerformanceResultCollector
  required-type       : com.test.jmeter.logger.PerformanceResultCollector
  converter-type      : org.apache.jmeter.save.converters.TestElementConverter
  path                : /jmeterTestPlan/hashTree/hashTree/hashTree/com.test.jmeter.logger.PerformanceResultCollector
  line number         : 379
  class[1]            : org.apache.jorphan.collections.ListedHashTree
  converter-type[1]   : org.apache.jmeter.save.converters.HashTreeConverter
  ------------------------------- : java.lang.NullPointerException : java.lang.NullPointerException
  ---- Debugging information ----
  message             : java.lang.NullPointerException
  cause-exception     : java.lang.RuntimeException
  cause-message       : java.lang.NullPointerException
  class               : com.test.jmeter.logger.PerformanceResultCollector
  required-type       : com.test.jmeter.logger.PerformanceResultCollector
  converter-type      : org.apache.jmeter.save.converters.TestElementConverter
  path                : /jmeterTestPlan/hashTree/hashTree/hashTree/com.test.jmeter.logger.PerformanceResultCollector
  line number         : 379
  class[1]            : org.apache.jorphan.collections.ListedHashTree
  converter-type[1]   : org.apache.jmeter.save.converters.HashTreeConverter
  </code></pre>
  
  <p>In the log, I find that it has alreay come into the construct function of PerformanceResultCollector. But why it throw the NulPointerException. I confirm the lib of jmeter on Linux is same as on Windows. Can anyone tell me what's wrong with my listener? Many thanks</p>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <p>After I have modified my code many times, I finally know how to resolve it, even through I don't know the reason. In the PerformanceResultCollector.class, if I construct the lazy CustomCollector, it works.</p>
  
  <pre><code>public class PerformanceResultCollector extends ResultCollector implements Serializable {    
  CustomCollector collector;
  
  public PerformanceResultCollector() {    
    log.info("construct performance collector")
  
  }
  @Override
  public void sampleOccurred(SampleEvent e) {
  if (null == collector) {
      collector = new CustomCollector();
  }
  collector.addSample(e.getResult());
  }
  
  public void cleanUp(){
      CustomCollector.cleanUp();
  }
  }
  </code></pre>
  
  <p>Maybe the JMeter parses the jmx script in different ways for non-gui and gui mode. </p>