From 4969a1ad33999c55e4468878ee3316e3a6cfd580 Mon Sep 17 00:00:00 2001 From: dl Date: Mon, 20 Jun 2011 12:27:20 +0100 Subject: [PATCH] 7051516: ThreadLocalRandom seed is never initialized so all instances generate the same sequence Reviewed-by: chegar, dholmes, mduigou --- src/share/classes/java/util/Random.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/share/classes/java/util/Random.java b/src/share/classes/java/util/Random.java index 447c41655..e56051cbd 100644 --- a/src/share/classes/java/util/Random.java +++ b/src/share/classes/java/util/Random.java @@ -118,7 +118,13 @@ class Random implements java.io.Serializable { * @see #setSeed(long) */ public Random(long seed) { - this.seed = new AtomicLong(initialScramble(seed)); + if (getClass() == Random.class) + this.seed = new AtomicLong(initialScramble(seed)); + else { + // subclass might have overriden setSeed + this.seed = new AtomicLong(); + setSeed(seed); + } } private static long initialScramble(long seed) { -- GitLab