commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Closed: (LANG-552) StringUtils replaceEach - Bug or Missing Documentation
Date Mon, 14 Dec 2009 07:53:18 GMT

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

Henri Yandell closed LANG-552.
------------------------------

    Resolution: Fixed

I dug more into the code and the intent appears to be that null in the replacement list is
ignored. I've null protected the part that was dying and new tests pass.

svn ci -m "Applying fix for LANG-552. StringUtils.replaceEach(String, String[], String[])
no longer NPEs when null appears in the last String[]"
Sending        src/java/org/apache/commons/lang3/StringUtils.java
Sending        src/test/org/apache/commons/lang3/StringUtilsTest.java
Transmitting file data ..
Committed revision 890212.




> StringUtils replaceEach - Bug or Missing Documentation 
> -------------------------------------------------------
>
>                 Key: LANG-552
>                 URL: https://issues.apache.org/jira/browse/LANG-552
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>            Reporter: Fabian Lange
>             Fix For: 3.0
>
>
> The following Test Case for replaceEach fails with a null pointer exception.
> I have expected that all StringUtils methods are "null-friendly"
> The use case is that i will stuff Values into the replacementList of which I do not want
to check whether they are null.
> I admit the use case is not perfect, because it is unclear what happens on the replace.
> I outlined three expectations in the test case, of course only one should be met.
> If it is decided that none of them should be possible, I propose to update the documentation
with what happens when null is passed as replacement string
> {code}
> import static org.junit.Assert.assertEquals;
> import org.apache.commons.lang.StringUtils;
> import org.junit.Test;
> public class StringUtilsTest {
> 	@Test
> 	public void replaceEach(){
> 		String original = "Hello World!";
> 		String[] searchList = {"Hello", "World"};
> 		String[] replacementList = {"Greetings", null};
> 		String result = StringUtils.replaceEach(original, searchList, replacementList);
> 		assertEquals("Greetings !", result);
> 		//perhaps this is ok as well
>                 //assertEquals("Greetings World!", result);
>                 //or even
> 		//assertEquals("Greetings null!", result);
> 	}
> 	
> }
> {code}

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


Mime
View raw message