Skip to content

Commit

Permalink
Deprecate static RandomStringUtils.random*() methods in favor or
Browse files Browse the repository at this point in the history
.secure() and .insecure() versions
  • Loading branch information
garydgregory committed Aug 8, 2024
1 parent f3de6a4 commit 69cb996
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The <action> type attribute can be add,update,fix,remove.
<release version="3.16.1" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate static RandomUtils.next*() methods in favor or .secure() and .insecure() versions.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate static RandomStringUtils.random*() methods in favor or .secure() and .insecure() versions.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Make RandomUtils.insecure() public.</action>
<!-- UPDATE -->
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/apache/commons/lang3/RandomStringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public static RandomStringUtils insecure() {
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String random(final int count) {
return secure().next(count);
}
Expand All @@ -124,7 +126,9 @@ public static String random(final int count) {
* @param numbers if {@code true}, generated string may include numeric characters
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String random(final int count, final boolean letters, final boolean numbers) {
return secure().next(count, letters, numbers);
}
Expand All @@ -140,7 +144,9 @@ public static String random(final int count, final boolean letters, final boolea
* @param chars the character array containing the set of characters to use, may be null
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String random(final int count, final char... chars) {
return secure().next(count, chars);
}
Expand All @@ -159,7 +165,9 @@ public static String random(final int count, final char... chars) {
* @param numbers if {@code true}, generated string may include numeric characters
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String random(final int count, final int start, final int end, final boolean letters,
final boolean numbers) {
return secure().next(count, start, end, letters, numbers);
Expand All @@ -183,7 +191,9 @@ public static String random(final int count, final int start, final int end, fin
* @return the random string
* @throws ArrayIndexOutOfBoundsException if there are not {@code (end - start) + 1} characters in the set array.
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String random(final int count, final int start, final int end, final boolean letters,
final boolean numbers, final char... chars) {
return secure().next(count, start, end, letters, numbers, chars);
Expand Down Expand Up @@ -219,7 +229,9 @@ public static String random(final int count, final int start, final int end, fin
* @throws ArrayIndexOutOfBoundsException if there are not {@code (end - start) + 1} characters in the set array.
* @throws IllegalArgumentException if {@code count} &lt; 0 or the provided chars array is empty.
* @since 2.0
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String random(int count, int start, int end, final boolean letters, final boolean numbers,
final char[] chars, final Random random) {
if (count == 0) {
Expand Down Expand Up @@ -361,7 +373,9 @@ public static String random(int count, int start, int end, final boolean letters
* @param chars the String containing the set of characters to use, may be null, but must not be empty
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0 or the string is empty.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String random(final int count, final String chars) {
return secure().next(count, chars);
}
Expand All @@ -376,7 +390,9 @@ public static String random(final int count, final String chars) {
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomAlphabetic(final int count) {
return secure().nextAlphabetic(count);
}
Expand All @@ -392,7 +408,9 @@ public static String randomAlphabetic(final int count) {
* @param maxLengthExclusive the exclusive maximum length of the string to generate
* @return the random string
* @since 3.5
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomAlphabetic(final int minLengthInclusive, final int maxLengthExclusive) {
return secure().nextAlphabetic(minLengthInclusive, maxLengthExclusive);
}
Expand All @@ -407,7 +425,9 @@ public static String randomAlphabetic(final int minLengthInclusive, final int ma
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomAlphanumeric(final int count) {
return secure().nextAlphanumeric(count);
}
Expand All @@ -423,7 +443,9 @@ public static String randomAlphanumeric(final int count) {
* @param maxLengthExclusive the exclusive maximum length of the string to generate
* @return the random string
* @since 3.5
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomAlphanumeric(final int minLengthInclusive, final int maxLengthExclusive) {
return secure().nextAlphanumeric(minLengthInclusive, maxLengthExclusive);
}
Expand All @@ -439,7 +461,9 @@ public static String randomAlphanumeric(final int minLengthInclusive, final int
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomAscii(final int count) {
return secure().nextAscii(count);
}
Expand All @@ -456,7 +480,9 @@ public static String randomAscii(final int count) {
* @param maxLengthExclusive the exclusive maximum length of the string to generate
* @return the random string
* @since 3.5
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomAscii(final int minLengthInclusive, final int maxLengthExclusive) {
return secure().nextAscii(minLengthInclusive, maxLengthExclusive);
}
Expand All @@ -473,7 +499,9 @@ public static String randomAscii(final int minLengthInclusive, final int maxLeng
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @since 3.5
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomGraph(final int count) {
return secure().nextGraph(count);
}
Expand All @@ -489,7 +517,9 @@ public static String randomGraph(final int count) {
* @param maxLengthExclusive the exclusive maximum length of the string to generate
* @return the random string
* @since 3.5
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomGraph(final int minLengthInclusive, final int maxLengthExclusive) {
return secure().nextGraph(minLengthInclusive, maxLengthExclusive);
}
Expand All @@ -504,7 +534,9 @@ public static String randomGraph(final int minLengthInclusive, final int maxLeng
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomNumeric(final int count) {
return secure().nextNumeric(count);
}
Expand All @@ -520,7 +552,9 @@ public static String randomNumeric(final int count) {
* @param maxLengthExclusive the exclusive maximum length of the string to generate
* @return the random string
* @since 3.5
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomNumeric(final int minLengthInclusive, final int maxLengthExclusive) {
return secure().nextNumeric(minLengthInclusive, maxLengthExclusive);
}
Expand All @@ -537,7 +571,9 @@ public static String randomNumeric(final int minLengthInclusive, final int maxLe
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @since 3.5
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomPrint(final int count) {
return secure().nextPrint(count);
}
Expand All @@ -553,7 +589,9 @@ public static String randomPrint(final int count) {
* @param maxLengthExclusive the exclusive maximum length of the string to generate
* @return the random string
* @since 3.5
* @deprecated Use {@link #secure()} or {@link #insecure()}.
*/
@Deprecated
public static String randomPrint(final int minLengthInclusive, final int maxLengthExclusive) {
return secure().nextPrint(minLengthInclusive, maxLengthExclusive);
}
Expand Down

0 comments on commit 69cb996

Please sign in to comment.