# HG changeset patch # User martin # Date 1275526434 25200 # Node ID f66c0faf01842f3c914cee4f527efd575ada08a8 # Parent 030ac5c2e62c5f06e4d204881d1a145c3992b734 6955840: ThreadLocalRandom bug - overriden setSeed(long) method is not invoked for java.util.Random(long) Summary: Allow setSeed only during construction Reviewed-by: dl, dholmes diff -r 030ac5c2e62c -r f66c0faf0184 jdk/src/share/classes/java/util/concurrent/ThreadLocalRandom.java --- a/jdk/src/share/classes/java/util/concurrent/ThreadLocalRandom.java Wed Jun 02 09:35:32 2010 +0100 +++ b/jdk/src/share/classes/java/util/concurrent/ThreadLocalRandom.java Wed Jun 02 17:53:54 2010 -0700 @@ -73,10 +73,10 @@ private long rnd; /** - * Initialization flag to permit the first and only allowed call - * to setSeed (inside Random constructor) to succeed. We can't - * allow others since it would cause setting seed in one part of a - * program to unintentionally impact other usages by the thread. + * Initialization flag to permit calls to setSeed to succeed only + * while executing the Random constructor. We can't allow others + * since it would cause setting seed in one part of a program to + * unintentionally impact other usages by the thread. */ boolean initialized; @@ -98,11 +98,10 @@ /** * Constructor called only by localRandom.initialValue. - * We rely on the fact that the superclass no-arg constructor - * invokes setSeed exactly once to initialize. */ ThreadLocalRandom() { super(); + initialized = true; } /** @@ -123,7 +122,6 @@ public void setSeed(long seed) { if (initialized) throw new UnsupportedOperationException(); - initialized = true; rnd = (seed ^ multiplier) & mask; }