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

Jochen Theodorou commented on GROOVY-7413:
------------------------------------------

This is the behavior of the standard Java method. You suggestion would require 
us providing our own version instead of the standard method, for which we 
should have really good reasons. A NPE might not be ideal, but is ok in my eyes.

> String.replaceFirst - bad behavior for null objects
> ---------------------------------------------------
>
>                 Key: GROOVY-7413
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7413
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>         Environment: *
>            Reporter: Maik Igloffstein
>
> h3. Unit-Tests
> {code}
> ​assert "tEst" == "test".replaceFirst("e", "E");​​​​​​​​​​​​​​​​​​​
> ​​assert "tEst" == "test".replaceFirst("e", null);​​​​​​​​​​​​​​​​​​​ 
> //throws: java.lang.NullPointerException
> ​​assert "tEst" == "test".replaceFirst(null, 
> "E");​​​​​​​​​​​​​​​​​​​//throws: java.lang.NullPointerException
> ​assert "tEst" == "test".replaceFirst(null, 
> null);​​​​​​​​​​​​​​​​​​​//throws: java.lang.NullPointerException
> {code}
> h3. Solutions
> In my private opinion, throwing a null pointer exception isn't the best way 
> here.
> possible Solutions:
> * IllegalArgumentException
> * no replacement - just return and do nothing



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to