Skip to content

Two fixes in RandomStringUtils.random(int, int, int, boolean, boolean, char[], Random)#1638

Merged
garydgregory merged 1 commit intoapache:masterfrom
garydgregory:bugfix/RandomStringUtils_random
May 7, 2026
Merged

Two fixes in RandomStringUtils.random(int, int, int, boolean, boolean, char[], Random)#1638
garydgregory merged 1 commit intoapache:masterfrom
garydgregory:bugfix/RandomStringUtils_random

Conversation

@garydgregory
Copy link
Copy Markdown
Member

Two fixes in RandomStringUtils.random(int, int, int, boolean, boolean, char[], Random)

  • A custom chars array throws IllegalArgumentException because validation loops treat the loop index as a char code point instead of an index into the chars array.
  • random() hangs when the specified [start, end) range contains ONLY rejected code points (UNASSIGNED, PRIVATE_USE, SURROGATE). The loop increments count and retries indefinitely.

Thanks for your contribution to Apache Commons! Your help is appreciated!

Before you push a pull request, review this list:

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • Contributor (OP) used AI to create any part of, or all of, the original report.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

char[], Random)

- A custom chars array throws IllegalArgumentException because
validation loops treat the loop index as a char code point instead of an
index into the chars array.
- random() hangs when the specified [start, end) range contains ONLY
rejected code points (UNASSIGNED, PRIVATE_USE, SURROGATE). The loop
increments count and retries indefinitely.
@garydgregory garydgregory merged commit 313d877 into apache:master May 7, 2026
49 of 52 checks passed
@garydgregory garydgregory deleted the bugfix/RandomStringUtils_random branch May 7, 2026 12:08
garydgregory added a commit that referenced this pull request May 7, 2026
Author: Gary Gregory <garydgregory@users.noreply.github.com> 2026-05-07
08:08:51
Committer: GitHub <noreply@github.com> 2026-05-07 08:08:51
Parent: e63927a (Annotation lookup
matches unrelated overloads via assignable-parameter resolution (#1637))
Branches: master, origin/HEAD, origin/master

Two fixes in RandomStringUtils.random(int, int, int, boolean, boolean,
(#1638)

char[], Random)

- A custom chars array throws IllegalArgumentException because
validation loops treat the loop index as a char code point instead of an
index into the chars array.
- random() hangs when the specified [start, end) range contains ONLY
rejected code points (UNASSIGNED, PRIVATE_USE, SURROGATE). The loop
increments count and retries indefinitely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant