8263978: Clarify why 0 argument is ignored in SecureRandom::setSeed

Reviewed-by: valeriep
This commit is contained in:
Weijun Wang 2021-03-23 22:23:37 +00:00
parent 15bcf6d9f5
commit 0b2aa1b605

View file

@ -730,10 +730,11 @@ public class SecureRandom extends java.util.Random {
@Override
public void setSeed(long seed) {
/*
* Ignore call from super constructor (as well as any other calls
* unfortunate enough to be passing 0). It's critical that we
* ignore call from superclass constructor, as digest has not
* yet been initialized at that point.
* Ignore call from super constructor as well as any other calls
* unfortunate enough to be passing 0. All SecureRandom
* constructors call `super(0)` which leads to `setSeed(0)`.
* We either keep the object unseeded (in `new SecureRandom()`)
* or we seed the object explicitly (in `new SecureRandom(byte[])`).
*/
if (seed != 0) {
setSeed(longToByteArray(seed));