You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/06/15 12:00:43 UTC
(commons-lang) branch master updated (86ed42da5 -> 2780ad699)
This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
from 86ed42da5 Fix RandomStringUtils.random() false rejection of letters and digits (#1703)
new 8ee047781 Javadoc
new 5fceb9271 Merge branch 'master' of https://garydgregory@github.com/apache/commons-lang.git
new 2780ad699 Fix RandomStringUtils.random() false rejection of letters and digits (#1703).
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 1 +
.../java/org/apache/commons/lang3/ArrayUtils.java | 2 +-
.../commons/lang3/RandomStringUtilsTest.java | 60 +++++++++++-----------
3 files changed, 32 insertions(+), 31 deletions(-)
(commons-lang) 03/03: Fix RandomStringUtils.random() false rejection of letters and digits (#1703).
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 2780ad699014d6ce9c7141b15c45bb2c806ef173
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jun 15 12:00:37 2026 +0000
Fix RandomStringUtils.random() false rejection of letters and digits
(#1703).
Sort members
---
src/changes/changes.xml | 1 +
.../commons/lang3/RandomStringUtilsTest.java | 60 +++++++++++-----------
2 files changed, 31 insertions(+), 30 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f76c6f675..dc87f2991 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -187,6 +187,7 @@ java.lang.NullPointerException: Cannot invoke
<action type="fix" dev="ggregory" due-to="alhudz">Fix int overflow in StringUtils.midString() and StrBuilder.midString() length handling (#1699).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory, Javid Khan">Throw IllegalArgumentException for trailing whitespace in ExtendedMessageFormat argument index (#1701).</action>
<action type="fix" dev="ggregory" due-to="alhudz, Gary Gregory">Reject doubled leading sign in NumberUtils.createBigInteger (#1702).</action>
+ <action type="fix" dev="ggregory" due-to="alhudz, Gary Gregory">Fix RandomStringUtils.random() false rejection of letters and digits (#1703).</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add JavaVersion.JAVA_27.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_27.</action>
diff --git a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
index 2c6a29181..ab0c3717f 100644
--- a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
@@ -119,36 +119,6 @@ public void testCustomLetterCharsArrayDoesNotThrowIAE() {
}, "RandomStringUtils.random() threw IAE for valid letter chars array - pre-patch behavior");
}
- /**
- * Asking for {@code letters && digits} must never be stricter than asking for {@code digits} alone. The range
- * {@code ['0', 'A')} holds the digits but no letters, so {@code random(count, '0', 'A', true, true, ...)} must
- * generate digits like the digits-only call over the same range, not throw IllegalArgumentException.
- */
- @Test
- void testLettersAndDigitsOverDigitOnlyRange() {
- final String both = RandomStringUtils.random(100, '0', 'A', true, true, null, new Random(42));
- assertEquals(100, both.length());
- for (final char c : both.toCharArray()) {
- assertTrue(c >= '0' && c <= '9', () -> "Expected a digit but got: " + c);
- }
- // digits alone already works over this range, so letters && digits must not reject it
- assertDoesNotThrow(() -> RandomStringUtils.random(100, '0', 'A', false, true, null, new Random(42)));
- }
-
- /**
- * The {@code letters && digits} ASCII fast path clamps {@code start} up to {@code '0'} and {@code end} down to
- * {@code 'z' + 1}. A range sitting entirely above the alphanumerics, e.g. {@code ['z' + 1, 0x7f)}, collapses to
- * {@code start >= end} after that clamp. It must throw a clear range IllegalArgumentException, not fall through to
- * {@code nextBits(0)} which reports the unrelated "number of bits must be between 1 and 32".
- */
- @Test
- void testLettersAndDigitsOverEmptyAsciiRange() {
- final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
- () -> RandomStringUtils.random(10, 'z' + 1, 0x7f, true, true, null, new Random(42)));
- assertTrue(e.getMessage() != null && !e.getMessage().contains("number of bits"),
- () -> "Expected a range-validation message but got: " + e.getMessage());
- }
-
@Test
void testExceptionsRandom() {
assertIllegalArgumentException(() -> RandomStringUtils.random(-1));
@@ -367,6 +337,36 @@ void testLANG807(final RandomStringUtils rsu) {
assertTrue(msg.contains("end"), "Message (" + msg + ") must contain 'end'");
}
+ /**
+ * Asking for {@code letters && digits} must never be stricter than asking for {@code digits} alone. The range
+ * {@code ['0', 'A')} holds the digits but no letters, so {@code random(count, '0', 'A', true, true, ...)} must
+ * generate digits like the digits-only call over the same range, not throw IllegalArgumentException.
+ */
+ @Test
+ void testLettersAndDigitsOverDigitOnlyRange() {
+ final String both = RandomStringUtils.random(100, '0', 'A', true, true, null, new Random(42));
+ assertEquals(100, both.length());
+ for (final char c : both.toCharArray()) {
+ assertTrue(c >= '0' && c <= '9', () -> "Expected a digit but got: " + c);
+ }
+ // digits alone already works over this range, so letters && digits must not reject it
+ assertDoesNotThrow(() -> RandomStringUtils.random(100, '0', 'A', false, true, null, new Random(42)));
+ }
+
+ /**
+ * The {@code letters && digits} ASCII fast path clamps {@code start} up to {@code '0'} and {@code end} down to
+ * {@code 'z' + 1}. A range sitting entirely above the alphanumerics, e.g. {@code ['z' + 1, 0x7f)}, collapses to
+ * {@code start >= end} after that clamp. It must throw a clear range IllegalArgumentException, not fall through to
+ * {@code nextBits(0)} which reports the unrelated "number of bits must be between 1 and 32".
+ */
+ @Test
+ void testLettersAndDigitsOverEmptyAsciiRange() {
+ final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+ () -> RandomStringUtils.random(10, 'z' + 1, 0x7f, true, true, null, new Random(42)));
+ assertTrue(e.getMessage() != null && !e.getMessage().contains("number of bits"),
+ () -> "Expected a range-validation message but got: " + e.getMessage());
+ }
+
/**
* Test {@code RandomStringUtils.random} works appropriately when letters=true
* and the range does not only include ASCII letters.
(commons-lang) 02/03: Merge branch 'master' of https://garydgregory@github.com/apache/commons-lang.git
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 5fceb927149723bc6199d46f3a5f27675e65d9db
Merge: 8ee047781 86ed42da5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jun 15 11:58:08 2026 +0000
Merge branch 'master' of https://garydgregory@github.com/apache/commons-lang.git
.../apache/commons/lang3/RandomStringUtils.java | 10 +++++++-
.../lang3/compare/ObjectToStringComparator.java | 2 +-
.../commons/lang3/RandomStringUtilsTest.java | 30 ++++++++++++++++++++++
.../compare/ObjectToStringComparatorTest.java | 24 +++++++++++++++++
4 files changed, 64 insertions(+), 2 deletions(-)
(commons-lang) 01/03: Javadoc
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 8ee0477816221dbb67139db7e0dff6f997f9be9e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jun 15 02:37:10 2026 +0000
Javadoc
---
src/main/java/org/apache/commons/lang3/ArrayUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index 3e95e7326..4b6b2cf0b 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -4978,7 +4978,7 @@ public static <T> T[] nullToEmpty(final T[] array, final Class<T[]> type) {
}
/**
- * Gets the {@link ThreadLocalRandom} for {@code shuffle} methods that don't take a {@link Random} argument.
+ * Gets the current thread's {@link ThreadLocalRandom} for {@code shuffle} methods that don't take a {@link Random} argument.
*
* @return the current ThreadLocalRandom.
*/