[concurrency-interest] Funny ThreadLocalRandom Bug in Random :-)

Ismael Juma mlists at juma.me.uk
Wed Jan 4 14:24:45 EST 2012


On Wed, Jan 4, 2012 at 7:18 PM, Dr Heinz M. Kabutz <heinz at javaspecialists.eu
> wrote:

> What started as a quest to write a little Phaser demo, ended up as a chase
> through the Java 7 source code to find a fun bug.  Turns out that in the
> version of Java 7 that I am using (on the Mac OS X, unofficial build, build
> 1.7.0-ea-b221), there is a bug in Random.  In the constructor, it should
> have said:
>
>   public Random(long seed) {
>       this.seed = new AtomicLong();
>       setSeed(initialScramble(seed))**;
>   }
>
> But instead, they just do:
>
>   public Random(long seed) {
>       this.seed = new AtomicLong(initialScramble(**seed));
>   }
>

In Java 7 update 2:

    public Random(long seed) {
        if (getClass() == Random.class)
            this.seed = new AtomicLong(initialScramble(seed));
        else {
            // subclass might have overriden setSeed
            this.seed = new AtomicLong();
            setSeed(seed);
        }
    }

Best,
Ismael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120104/2e48dcc1/attachment.html>


More information about the Concurrency-interest mailing list