[ https://issues.apache.org/jira/browse/LANG-1406?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16839056#comment-16839056 ]
Gerardo Torres Ontiveros edited comment on LANG-1406 at 5/14/19 3:55 AM: ------------------------------------------------------------------------- This error happens in StringUtils.replace and can be fixed using StringUtils.indexOfIgnoreCase instead of converting first to lower case with the native String method and using the String native indexOf method. The method StringUtils.indexOfIgnoreCase resolves the problem because converts and compare the characters individually. But will be some consequences to using indexOfIgnoreCase because is not Locale sensitive, it uses Character.toLowerCase() that is not Locale sensitive as String.toLowerCase(). Thus Turkish words or other language words could be treated incorrectly. The solution I pose is to change the use of Character.toLowerCase to String.toLowerCase and upperCase in order to handle the Strings with a Locale. I created this pull request https://github.com/apache/commons-lang/pull/422. I invite you to check it and give some feedback. was (Author: gtorres): This error happens in StringUtils.replace and can be fixed using StringUtils.indexOfIgnoreCase instead of converting first to lower case with the native String method and using the String native indexOf method. The method StringUtils.indexOfIgnoreCase resolves the problem because converts and compare the characters individually. But will be some consequences to using indexOfIgnoreCase because is not Locale sensitive, it uses Character.toLowerCase() that is not Locale sensitive as String.toLowerCase(). Thus Turkish words or other language words could be treated incorrectly. The solution I pose is to change the use of Character.toLowerCase to String.toLowerCase and upperCase in order to handle the Strings with a Locale. I created [this|[https://github.com/apache/commons-lang/pull/422]] pull request. I invite you to check it and give some feedback. > StringIndexOutOfBoundsException in StringUtils.replaceIgnoreCase > ---------------------------------------------------------------- > > Key: LANG-1406 > URL: https://issues.apache.org/jira/browse/LANG-1406 > Project: Commons Lang > Issue Type: Bug > Components: lang.* > Reporter: Michael Ryan > Priority: Major > Time Spent: 40m > Remaining Estimate: 0h > > STEPS TO REPRODUCE: > {code} > StringUtils.replaceIgnoreCase("\u0130x", "x", "") > {code} > EXPECTED: "\u0130" is returned. > ACTUAL: StringIndexOutOfBoundsException > This happens because the replace method is assuming that text.length() == > text.toLowerCase().length(), which is not true for certain characters. -- This message was sent by Atlassian JIRA (v7.6.3#76005)