commons-lang icon indicating copy to clipboard operation
commons-lang copied to clipboard

LANG-1801: Validate start/end bounds when chars is provided

Open Akshat-coder2106 opened this issue 1 week ago • 0 comments

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 start and end when chars != null
  • Ensured invalid ranges are rejected with IllegalArgumentException
  • Added unit tests to cover invalid start / end scenarios

##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.

Akshat-coder2106 avatar Dec 17 '25 05:12 Akshat-coder2106