harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Catherine Hope (JIRA)" <j...@apache.org>
Subject [jira] Updated: (HARMONY-6547) [classlib][luni] String.replace("", CharSequence) goes out of memory
Date Wed, 09 Jun 2010 13:50:14 GMT

     [ https://issues.apache.org/jira/browse/HARMONY-6547?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Catherine Hope updated HARMONY-6547:

    Attachment: 6547.patch

Patch adds a special case to String.replace(CharSequence, CharSequence) so that when the String
is "" the replacement string is inserted at the start, inbetween each character and at the
end.  I think this is a more readable alternative to modifying the existing algorithm which
uses the length of the string to match to move along the string, so when it is empty then
it doesn't make progress, but also there's a corner case of the loop condition because calling
mystring.indexOf("", mystring.length()+1) returns mystring.length() and not -1.

Also, small performance improvement for allocating the capacity of the StringBuilder as we
already know that the String has been matched once so the minimum size of the buffer is count+replacementString.length()
so this will avoid an immediate resize.

> [classlib][luni] String.replace("", CharSequence) goes out of memory
> --------------------------------------------------------------------
>                 Key: HARMONY-6547
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6547
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Catherine Hope
>            Priority: Minor
>         Attachments: 6547.patch
> Calling String.replace(CharSequence, CharSequence) with the empty String as the first
argument throws an OutOfMemoryError as it goes into an infinite loop trying to substitute
the sequence at the same point until the StringBuilder fills the heap.  The RI in this case
substitutes the replacement String at the start, inbetween each character and at the end.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message