You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (Updated) (JIRA)" <ji...@apache.org> on 2012/04/03 22:42:25 UTC

[jira] [Updated] (LANG-686) StringUtils.replaceEachRepeatedly("aaa", new String[]{"aa"}, new String[]{"aXa"}); throw an exception

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

Thomas Neidhart updated LANG-686:
---------------------------------

    Attachment: LANG-686.patch

I have worked on this a bit and provide a patch that does the following:

 * refactor the replaceEach method to avoid 
   code duplication
 * change loop detection code

Instead using a timeToLive variable that trys to detect infinite loops, I use a quite simple but effective method:

Whenever at the end of a replace cycle we end up having a result string that has already be seen so far, we have possibly detected an infinite loop and thus abort the execution (with an exception as before).

I have also added two additional unit test cases.
                
> StringUtils.replaceEachRepeatedly("aaa", new String[]{"aa"}, new String[]{"aXa"}); throw an exception
> -----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-686
>                 URL: https://issues.apache.org/jira/browse/LANG-686
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 2.6
>         Environment: jdk 1.6.24, windows xp pro sp3, eclipse helios
>            Reporter: qed
>             Fix For: 3.x
>
>         Attachments: LANG-686.patch
>
>
> After executing line
> StringUtils.replaceEachRepeatedly("aaa", new String[]{"aa"}, new String[]{"aXa"});
> exception is thrown:
> Exception in thread "main" java.lang.IllegalStateException: TimeToLive of -1 is less than 0: aXaXa
> 	at org.apache.commons.lang.StringUtils.replaceEach(StringUtils.java:3986)
> 	at org.apache.commons.lang.StringUtils.replaceEach(StringUtils.java:4099)
> 	at org.apache.commons.lang.StringUtils.replaceEach(StringUtils.java:4099)
> 	at org.apache.commons.lang.StringUtils.replaceEachRepeatedly(StringUtils.java:3920)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira