commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Farnsworth (JIRA)" <>
Subject [jira] [Created] (LANG-823) StringUtils.split should handle empty strings the same as other content
Date Thu, 13 Sep 2012 15:19:07 GMT
Mark Farnsworth created LANG-823:

             Summary: StringUtils.split should handle empty strings the same as other content
                 Key: LANG-823
             Project: Commons Lang
          Issue Type: Improvement
          Components: lang.*
    Affects Versions: 2.5
            Reporter: Mark Farnsworth
            Priority: Minor

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

For example,
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(" ",",")[0].equals(" "));
		// The following should also work but 
		// in commons-lang-2.5.jar the test fails here

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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message