Skip to content

Commit bd247e4

Browse files
committed
Use String.format()
1 parent 487ba4d commit bd247e4

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/main/java/org/apache/commons/lang3/RandomStringUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public static String random(int count, int start, int end, final boolean letters
258258
return StringUtils.EMPTY;
259259
}
260260
if (count < 0) {
261-
throw new IllegalArgumentException("Requested random string length " + count + " is less than 0.");
261+
throw new IllegalArgumentException(String.format("Requested random string length %,d is less than 0.", end));
262262
}
263263
if (chars != null && chars.length == 0) {
264264
throw new IllegalArgumentException("The chars array must not be empty");
@@ -273,7 +273,7 @@ public static String random(int count, int start, int end, final boolean letters
273273
start = ' ';
274274
}
275275
} else if (end <= start) {
276-
throw new IllegalArgumentException("Parameter end (" + end + ") must be greater than start (" + start + ")");
276+
throw new IllegalArgumentException(String.format("Parameter end (%,d) must be greater than start (%,d)", end, start));
277277
} else if (start < 0 || end < 0) {
278278
throw new IllegalArgumentException("Character positions MUST be >= 0");
279279
}
@@ -293,8 +293,9 @@ public static String random(int count, int start, int end, final boolean letters
293293
return random(count, 0, 0, false, false, ALPHANUMERICAL_CHARS, random);
294294
}
295295
if (digits && end <= ASCII_0 || letters && end <= ASCII_A) {
296-
throw new IllegalArgumentException("Parameter end (" + end + ") must be greater than (" + ASCII_0 + ") for generating digits "
297-
+ "or greater than (" + ASCII_A + ") for generating letters.");
296+
throw new IllegalArgumentException(
297+
String.format("Parameter end (%,d) must be greater than (%,d) for generating digits or greater than (%,d) for generating letters.",
298+
end, ASCII_0, ASCII_A));
298299
}
299300
// Optimize start and end when filtering by letters and/or numbers:
300301
// The range provided may be too large since we filter anyway afterward.

0 commit comments

Comments
 (0)