Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1719

RandomStringUtils.random outputs strings that are equal over and over

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.13.0
    • 3.15.0
    • lang.*
    • None
    • Samsung Smartphone

      Product name: Galaxy A53 5G

      Model name: SM-A536B/DS

      Software info:

      One UI version 5.1

      Android version 13

    Description

      The following line of code outputs equal strings over and over:

      RandomStringUtils.random(12,"abcdefghijklmnopqrstuvwxyz0123456789") 

      Steps to reproduce:
      1) Create a new Android project in Android Studio
      2) Add the following dependency to your gradle file

      implementation("org.apache.commons:commons-lang3:3.13.0") 

      3) Use the following code in your MainActivity:

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

      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:

      09:33:10.154 TAG                  tes...tringutils  D  m9mcx5ywuxdc
      09:33:28.561 TAG                  tes...tringutils  D  m9mcx5ywuxdc
      

      Using the previous commons-lang3 version in the project resolves the issue. Here are the steps to reproduce:
      1) Replace

      implementation("org.apache.commons:commons-lang3:3.13.0") 

      with

      implementation("org.apache.commons:commons-lang3:3.12.0") 

      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:

      09:40:50.268 TAG                  tes...tringutils  D  1tjkvkta6ibi
      09:40:55.324 TAG                  tes...tringutils  D  02nfvrf9pfgl

       

      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.

      Attachments

        Activity

          People

            ggregory Gary D. Gregory
            benjamin.glatzeder Benjamin Glatzeder
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: