In a "Random Variable" element set true the "Per Thread(User)" option, and launch test plan in distributed mode (Remote Start).
ERROR - jmeter.threads.JMeterThread: Test failed! java.lang.NullPointerException
at org.apache.jmeter.config.RandomVariableConfig.iterationStart(RandomVariableConfig.java:90)
at org.apache.jmeter.control.GenericController.fireIterationStart(GenericController.java:318)
at org.apache.jmeter.control.GenericController.fireIterEvents(GenericController.java:308)
at org.apache.jmeter.control.GenericController.next(GenericController.java:128)
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:182)
at org.apache.jmeter.control.GenericController.next(GenericController.java:146)
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:185)
at org.apache.jmeter.control.GenericController.next(GenericController.java:146)
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:182)
at org.apache.jmeter.control.GenericController.next(GenericController.java:146)
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:182)
at org.apache.jmeter.control.GenericController.next(GenericController.java:146)
at org.apache.jmeter.control.LoopController.next(LoopController.java:109)
at org.apache.jmeter.threads.ThreadGroup.next(ThreadGroup.java:129)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:242)
at java.lang.Thread.run(Unknown Source)
The method:
public void iterationStart(LoopIterationEvent iterEvent) {
Random randGen=null;
if (getPerThread()){
randGen = (Random) perThreadRandom.get(); <------ At line 90, the perThreadRandom object IS NULL.
} else {
synchronized(this){
if (globalRandom == null){
init();
globalRandom = new Random(getRandomSeedAsLong());
}
randGen=globalRandom;
}
}
if (n <=0){
return;
}
long nextRand = minimum + randGen.nextInt(n);
// Cannot use getThreadContext() as we are not cloned per thread
JMeterVariables variables = JMeterContextService.getContext().getVariables();
variables.put(getVariableName(), formatNumber(nextRand));
}
The declaration:
private transient ThreadLocal perThreadRandom = new ThreadLocal() {
protected Object initialValue() {
init();
return new Random(getRandomSeedAsLong());
}};
¿Why transient? Javadoc says that ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread. However, in this case not in possible, because init() and getRandomSeedAsLong() are non-static methods in the class. I comment out these calls, set static the declaration and work fine.
References: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ThreadLocal.html
I use: java version "1.6.0_14"

Thanks for the report.
The perThreadRandom field cannot be static.
There may be several instances of the Random Config element and each one needs its own PRNG.
The field must be transient for the same reason.
Solution is to use readResolve() to create the field.
URL: http://svn.apache.org/viewvc?rev=801478&view=rev
Log:
Bug 47646 - NullPointerException in the "Random Variable" element

This is ASF Bugzilla: the Apache Software Foundation bug system. In case
of problems with the functioning of ASF Bugzilla, please contact
bugzilla-admin@apache.org.
Please Note: this e-mail address is only for reporting problems
with ASF Bugzilla. Mail about any other subject will be silently
ignored.