commons-lang
commons-lang copied to clipboard
LANG-1801: Validate start/end bounds when chars is provided
What does this PR do?
This pull request fixes LANG-1801 by validating the start and end parameters
in RandomStringUtils.random() when a custom chars array is provided.
Previously, invalid values for start or end could result in an
ArrayIndexOutOfBoundsException. This change ensures that such invalid inputs
are detected early and an IllegalArgumentException is thrown instead, which
matches the documented method contract.
How was this implemented?
- Added explicit validation of
startandendwhenchars != null - Ensured invalid ranges are rejected with
IllegalArgumentException - Added unit tests to cover invalid
start/endscenarios
##Checklist
- [x] Read the contribution guidelines for this project.
- [x] Read the ASF Generative Tooling Guidance.
- [x] I used AI (ChatGPT) for guidance and explanations; all code and tests were written and reviewed by me.
- [x] Ran a successful build using the default Maven goal (
mvn). - [x] Added unit tests that fail without the fix and pass with the fix applied.
- [x] Provided a clear pull request description explaining what, how, and why.
- [x] Commits have meaningful subject lines and are related to LANG-1801.