You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by bu...@apache.org on 2009/08/05 12:24:59 UTC

DO NOT REPLY [Bug 47646] New: NullPointerException in the "Random Variable" element

https://issues.apache.org/bugzilla/show_bug.cgi?id=47646

           Summary: NullPointerException in the "Random Variable" element
           Product: JMeter
           Version: 2.3.4
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Main
        AssignedTo: jmeter-dev@jakarta.apache.org
        ReportedBy: mparreno@hp-cda.com


--- Comment #0 from Miguel Parreño <mp...@hp-cda.com> 2009-08-05 03:24:57 PDT ---
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"

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 47646] NullPointerException in the "Random Variable" element

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47646

Sebb <se...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #2 from Sebb <se...@apache.org> 2009-09-17 03:41:53 PDT ---
Resolved in SVN; code is in builds after (and including) r801478

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 47646] NullPointerException in the "Random Variable" element

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47646

froutier@cofisun.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |froutier@cofisun.com

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 47646] NullPointerException in the "Random Variable" element

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47646



--- Comment #1 from Sebb <se...@apache.org> 2009-08-05 17:32:32 PDT ---
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

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org