ppkarwasz commented on code in PR #1644:
URL: https://github.com/apache/commons-lang/pull/1644#discussion_r3247770185


##########
src/main/java/org/apache/commons/lang3/StringUtils.java:
##########
@@ -6117,7 +6117,12 @@ public static String repeat(final String repeat, final 
int count) {
         if (inputLength == 1 && count <= PAD_LIMIT) {
             return repeat(repeat.charAt(0), count);
         }
-        final int outputLength = inputLength * count;
+        final int outputLength;
+        try {
+            outputLength = Math.multiplyExact(inputLength, count);
+        } catch (final Exception e) {
+            throw new IllegalArgumentException("Count too large for input");

Review Comment:
   I agree that `OutOfMemoryError` is the wrong choice, but the difference 
prevents a smooth migration between `StringUtils` and newly introduced `String` 
methods. Maybe this is something worth documenting to explain users why they 
should not replace this method with `String.repeat`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to