On Fri, 25 Feb 2022 22:59:05 GMT, liach <d...@openjdk.java.net> wrote:

>> src/java.base/share/classes/java/util/Random.java line 298:
>> 
>>> 296:      */
>>> 297:     public static Random from(RandomGenerator random) {
>>> 298:         return RandomWrapper.wrap(random);
>> 
>> Might be good to check here or in the called methods / constructors for 
>> `null`. Currently `null` would not be noticed until the first method is 
>> called on the created `Random`, which makes it difficult for the user to 
>> track down bugs in their code.
>
> Suggestion:
> 
>         Objects.requireNonNull(random);
>         return RandomWrapper.wrap(random);
> 
> fyi this is the original change suggested by marcono1234. Notice that this 
> might need a csr update; maybe a javadoc update is needed too

Arguably, `RandomWrapper.wrap` should be inlined here, since it’s not used 
anywhere else:
Suggestion:

        if (Objects.requireNonNull(random, "random") instanceof Random) {
            return (Random) random;
        }
        return new RandomWrapper(random);

-------------

PR: https://git.openjdk.java.net/jdk/pull/7001

Reply via email to