[ 
https://issues.apache.org/jira/browse/RNG-192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18073532#comment-18073532
 ] 

Alex Herbert commented on RNG-192:
----------------------------------

This also affects abstract classes:
||Abstract base||Derived classes||
|AbstractPcg6432|PcgXshRr32; PcgXshRs32|
|AbstractXoRoShiRo64|XoRoShiRo64Star; XoRoShiRo64StarStar|
|AbstractXoShiRo128|XoShiRo128Plus; XoShiRo128PlusPlus; XoShiRo128StarStar|
|AbstractXoRoShiRo1024|XoRoShiRo1024PlusPlus; XoRoShiRo1024Star; 
XoRoShiRo1024StarStar|
|AbstractXoRoShiRo128|XoRoShiRo128Plus; XoRoShiRo128PlusPlus; XoRoShiRo128Star|
|AbstractXoShiRo256|XoShiRo256Plus; XoShiRo256PlusPlus; XoShiRo256StarStar|
|AbstractXoShiRo512|XoShiRo512Plus; XoShiRo512PlusPlus; XoShiRo512StarStar|

 

> 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
>
> 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