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

RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.5, 2.6, 3.1
    • 3.2, 2.7
    • None

    Description

      In commons-lang 2.6 line 250 :

      ch = chars[random.nextInt(gap) + start];

      This line of code takes a random int to fetch a char in the chars array regardless of its size.
      (Besides start is useless here)

      Fixed version would be :

      //ch = chars[random.nextInt(gap)%chars.length];

      When user pass 0 as end or when the array is not null but empty this line ends up with an exception

      Attachments

        Activity

          People

            Unassigned Unassigned
            thomas.belot Thomas BELOT
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified