[ 
https://issues.apache.org/jira/browse/RNG-192?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Herbert resolved RNG-192.
------------------------------
    Fix Version/s: 1.7
       Resolution: Implemented

Updated in commit:
 
a14cf2eec3cb392193c7be746c6ebdecead32551
 

> Remove use of overriddable instance method for state initialisation
> -------------------------------------------------------------------
>
>                 Key: RNG-192
>                 URL: https://issues.apache.org/jira/browse/RNG-192
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.6
>            Reporter: Alex Herbert
>            Priority: Trivial
>             Fix For: 1.7
>
>
> The {{org.apache.commons.rng.core.BaseProvider}} provides methods to fill a 
> state array using a seed array:
> {code:java}
> protected void fillState(int[] state, int[] seed)
> protected void fillState(long[] state, long[] seed)
> {code}
> If the seed is not long enough then it is extended using a random generator.
> The method is used in the constructor by:
>  * DotyHumphreySmallFastCounting32
>  * KISSRandom
>  * MultiplyWithCarry256
>  * DotyHumphreySmallFastCounting64
>  * PcgRxsMXs64
>  * XorShift1024Star
> This generates a compile time warning on JDK 21+: "possible 'this' escape 
> before subclass is fully initialized". This is due to this feature:
> [JDK-8299995: Add lint check for calling overridable methods from a 
> constructor|https://bugs.openjdk.org/browse/JDK-8299995]
> Since the method is a non-final protected instance method it is possible for 
> the method to be overridden by sub-classes to alter construction behaviour.
> h2. Solution
> Unexpected behaviour of partially initialised classes can be avoided by 
> altering the constructors to call the alternative seeding methods in the 
> {{BaseProvider}} to extend an input seed:
> {code:java}
> protected static long[] extendSeed(long[] seed, int length)
> protected static int[] extendSeed(int[] seed, int length)
> {code}
> This will introduce a behavioural change to the listed RNGs when used with a 
> seed that does not fill the entire state of the generator:
> Use of a fixed seed will change the output sequence. This may effect code 
> that relies on certain output, for example unit tests on pseudorandom data.
> Use of a random seed will continue to output a random sequence from the 
> generator.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to