mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-16 13:25:34 +00:00
6955840: ThreadLocalRandom bug - overriden setSeed(long) method is not invoked for java.util.Random(long)
Allow setSeed only during construction Reviewed-by: dl, dholmes
This commit is contained in:
parent
6d1572722f
commit
72ec2d876a
@ -73,10 +73,10 @@ public class ThreadLocalRandom extends Random {
|
||||
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 @@ public class ThreadLocalRandom extends Random {
|
||||
|
||||
/**
|
||||
* 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 class ThreadLocalRandom extends Random {
|
||||
public void setSeed(long seed) {
|
||||
if (initialized)
|
||||
throw new UnsupportedOperationException();
|
||||
initialized = true;
|
||||
rnd = (seed ^ multiplier) & mask;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user