commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <>
Subject [jira] [Commented] (MATH-899) A random crash of MersenneTwister random generator
Date Sun, 18 Nov 2012 19:38:58 GMT


Phil Steitz commented on MATH-899:

I think the reason that the unit test does not work is that Junit does not actually see the
exception.  The Executor will not propagate it.  Changing the body of the core method (and
other sigs, etc) to the following, I can get consistent failures when I execute with -Dtest=SynchronizedRandomGenratorTest

final RandomGenerator rng = new MersenneTwister();
final RandomGenerator wrapper = sync ? new SynchronizedRandomGenerator(rng) : rng;
final AtomicBoolean failed = new AtomicBoolean(false);
final ExecutorService exec = Executors.newFixedThreadPool(numThreads);
for (int i = 0; i < numGenerators; i++) {
    exec.execute(new Runnable() {
        public void run() {
            for (int j = 0; j < numSamples; j++) {
                try {
                } catch (ArrayIndexOutOfBoundsException ex) {
        exec.awaitTermination(100, TimeUnit.SECONDS);

What I don't understand is why this consistently succeeds when executed as a single test,
but usually fails when executed as part of the full test suite with
 mvn clean test

I would say in any case there is no need to add a unit test to show the non-thread-safety
of MersenneTwister or to verify that adding synchronization does what it says it does, i.e.,
I would say go ahead and commit the wrapper with no test class.
> A random crash of MersenneTwister random generator
> --------------------------------------------------
>                 Key: MATH-899
>                 URL:
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7, JDK 1.7.05
>            Reporter: Alexander Nozik
>            Priority: Minor
>         Attachments:,
> There is a very small probability that MersenneTwister generator gives a following error:

> java.lang.ArrayIndexOutOfBoundsException: 624
> in line 253
> The error is completely random and its probability is about 1e-8.
> UPD: The problem most probably arises only in multy-thread mode.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message