[ 
https://issues.apache.org/jira/browse/LANG-1824?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18079246#comment-18079246
 ] 

Gary D. Gregory edited comment on LANG-1824 at 5/7/26 7:32 PM:
---------------------------------------------------------------

In git master, running this test, a request for such a huge string gives me an 
{{{}java.lang.OutOfMemoryError: Java heap space{}}}, no surprise there.


was (Author: garydgregory):
In git master, a request for such a huge string gives me an 
\{{java.lang.OutOfMemoryError: Java heap space}}, no surprise there.

> NegativeArraySizeException thrown from Strings.replace with larger replacement
> ------------------------------------------------------------------------------
>
>                 Key: LANG-1824
>                 URL: https://issues.apache.org/jira/browse/LANG-1824
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.20.0
>            Reporter: Veijo Vainionpää
>            Priority: Major
>
> NegativeArraySizeException thrown from Strings.replace with larger 
> replacement when {{replacement.length() - searchString.length()}} is bigger 
> than 134217727 bytes (~132 MB).
> {{public String replace(final String text, String searchString, final String 
> replacement, int max) {}}
> {{...}}
> {{final int replLength = searchString.length();}}
> {{int increase = Math.max(replacement.length() - replLength, 0);}}
> {{increase *= max < 0 ? 16 : Math.min(max, 64);}}
> {{final StringBuilder buf = new StringBuilder(text.length() + increase);}}
> {{...}}
> {{}}}
> The main reason is that the integer overflows after multiplication.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to