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

Benedikt Ritter commented on LANG-823:
--------------------------------------

Hello Efthymis,

I've reviewed your patch. I see that you have modified the JavaDoc of 
{{StringUtils}} to reflect the desired behavior. However you haven't changes 
the actual splitting code. So all tests you provided fail.

We are still discussing this issue on the ML. The rationale behind returning an 
empty array is, that the empty string can not be matched. It is the lack of a 
token, so we return nothing.

If you have an arbitrary String, say "abc" and you match it against "x" we 
return ["abc"], because we tried to match "abc" against "x" and did not find a 
match, so we return the whole token.

I personally find it a bit counter intuitive to return an empty array if we 
match against the empty string, although I understand the reason for doing so.

> StringUtils.split should handle empty strings the same as other content
> -----------------------------------------------------------------------
>
>                 Key: LANG-823
>                 URL: https://issues.apache.org/jira/browse/LANG-823
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 2.5
>            Reporter: Mark Farnsworth
>            Assignee: Benedikt Ritter
>            Priority: Minor
>             Fix For: 3.3, Review Patch, Discussion
>
>         Attachments: LANG-823.patch, LANG-823.test.patch
>
>
> When a user issues a split with a delimiter and the string does not contain 
> the delimiter the result is normally an array with one item that contains the 
> content of the string.
> It seems strange that StringUtils does not behave consistently in the context 
> of an empty string.
> For example,
> {code}
> package maf.test;
> import junit.framework.TestCase;
> import org.apache.commons.lang.StringUtils;
> public class StringUtilsTest extends TestCase {
>       public void testStringUtils() {
>               // The following two lines work correctly  
>               assertTrue(StringUtils.split("x",",")[0].equals("x"));
>               assertTrue(StringUtils.split(" ",",")[0].equals(" "));
>               
>               // The following should also work but 
>               // in commons-lang-2.5.jar the test fails here
>               assertTrue(StringUtils.split("",",")[0].equals("")); 
>       }
> }
> {code}
> There seems to be no logic behind making split work differently in the case 
> of empty strings.  
> For the next release, I would suggest a behavior change for StringUtils this 
> will have side effects but would be more logically consistent.  
> Users who depend on the old behavior could stick with 2.5 release and/or 
> implement code in the caller to simulate the behavior.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to