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

Benjamin Glatzeder commented on LANG-1719:
------------------------------------------

I can confirm that java.util.concurrent.ThreadLocalRandom keeps printing the 
same number sequence after an app restart on Android version 33 and below.

Code snippet:
{code:java}
for (i in 0..9) {
    Log.d(TAG,"random ${ThreadLocalRandom.current().nextInt()}")
} {code}
On the contrary on Android version 34 the issue is fixed.
{code:java}
for (i in 0..9) {
    Log.d(TAG,"random ${ThreadLocalRandom.current().nextInt()}") // prints 
different number sequences after app restarts 
} {code}
{code:java}
val randomString = 
RandomStringUtils.random(12,"abcdefghijklmnopqrstuvwxyz0123456789")
Log.d(TAG, randomString) // prints random strings after app restarts 
{code}
 

Android 34 was released on Oct 4th 2023. It will be many years until the last 
Android users have a device running Android 34 or newer. Please don't take the 
following as a snarky comment but rather as more information. As an Android app 
developer I'm unable to push Android SDK updates via an app update. Every 
Android app developer who expects RandomUtils.random() to return random strings 
will run into the same issue as I have as soon as they update commons-lang3 
from version 3.12.0 to 3.13.0.

> RandomStringUtils.random outputs strings that are equal over and over
> ---------------------------------------------------------------------
>
>                 Key: LANG-1719
>                 URL: https://issues.apache.org/jira/browse/LANG-1719
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.13.0
>         Environment: Samsung Smartphone
> Product name: Galaxy A53 5G
> Model name: SM-A536B/DS
> Software info:
> One UI version 5.1
> Android version 13
>            Reporter: Benjamin Glatzeder
>            Priority: Major
>             Fix For: 3.12.0
>
>
> The following line of code outputs equal strings over and over:
> {code:java}
> RandomStringUtils.random(12,"abcdefghijklmnopqrstuvwxyz0123456789") {code}
> Steps to reproduce:
> 1) Create a new Android project in Android Studio
> 2) Add the following dependency to your gradle file
> {code:bash}
> implementation("org.apache.commons:commons-lang3:3.13.0") {code}
> 3) Use the following code in your MainActivity:
> {code:java}
> package test.randomstringutils
> import android.os.Bundle
> import android.util.Log
> import androidx.activity.ComponentActivity
> import org.apache.commons.lang3.RandomStringUtils
> class MainActivity : ComponentActivity() {
>     override fun onCreate(savedInstanceState : Bundle?) {
>         super.onCreate(savedInstanceState)
>         val randomString = 
> RandomStringUtils.random(12,"abcdefghijklmnopqrstuvwxyz0123456789")
>         Log.d(TAG, randomString)
>     }
>     companion object {
>         private const val TAG = "TAG"
>     }
> }
> {code}
> 4) Run project and note the string in Logcat
> 5) Run project again and compare the new random string in Logcat
> One will note that the strings are equal. The expected result should be that 
> the strings are not equal. Here's an example output:
> {code:java}
> 09:33:10.154 TAG                  tes...tringutils  D  m9mcx5ywuxdc
> 09:33:28.561 TAG                  tes...tringutils  D  m9mcx5ywuxdc
> {code}
> Using the previous commons-lang3 version in the project resolves the issue. 
> Here are the steps to reproduce:
> 1) Replace
> {code:bash}
> implementation("org.apache.commons:commons-lang3:3.13.0") {code}
> with
> {code:bash}
> implementation("org.apache.commons:commons-lang3:3.12.0") {code}
> 2) Click on "Sync now"
> 3) Run project and note the string in Logcat
> 4) Run project again and compare the new random string in Logcat
> One will note that the strings are not equal. This is the expected result. 
> Here's an example output:
> {code:java}
> 09:40:50.268 TAG                  tes...tringutils  D  1tjkvkta6ibi
> 09:40:55.324 TAG                  tes...tringutils  D  02nfvrf9pfgl{code}
>  
> I was able to consistently reproduce this issue using a Samsung Galaxy A53 5G 
> smartphone as well as on an Android Virtual Device (AVD). To the best of my 
> knowledge the smartphone runs on an ARM processor and the AVD has an emulated 
> ARM processor.
> I was *not* able to reproduce this issue when I created a Kotlin project in 
> IntelliJ with similar lines of code which was running on my Windows machine 
> with an x64 processor.



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

Reply via email to