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

Duncan Jones commented on LANG-842:
-----------------------------------

The {{equals}} methods must return {{false}}, [by 
contract|http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals%28java.lang.Object%29]:

bq. For any non-null reference value {{x, x.equals(null)}} should return 
{{false}}.

This makes sense, as nothing equals null - the correct answer is returned.

But for all other methods, it's quite standard to throw a runtime exception on 
a null argument. Take, for example, {{DateUtils.truncatedCompareTo}} - by its 
very design, the method must return a verdict on the differences between the 
two objects. There is no value that would be appropriate when one of the 
arguments is null. (You could argue a corner case when both arguments are null, 
but that's it).

Personally I would prefer to see {{NullPointerException}}, but I suspect this 
might be related to how the {{Validate}} class used to work pre 3.0.
                
> Lack of consistency in comparaison api
> --------------------------------------
>
>                 Key: LANG-842
>                 URL: https://issues.apache.org/jira/browse/LANG-842
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*, lang.time.*
>    Affects Versions: 3.2
>            Reporter: Pier-Luc Caron St-Pierre
>            Priority: Trivial
>
> The comparaison api is lacking of consistency with null.
> Few instances : 
> org.apache.commons.lang3.StringUtils#equals returns false if one of the 
> parameter is null.
> org.apache.commons.lang3.ObjectUtils#equals returns false if one of the 
> parameter is null.
> org.apache.commons.lang3.time.DateUtils#truncatedCompareTo throws 
> IllegalArgumentException if one of the parameter is null
> org.apache.commons.lang3.time.DateUtils#isSameInstant throws 
> IllegalArgumentException if one of the parameter is null
> I do not have any suggestion to fix that problem because any solution would 
> break backward compatibility.

--
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: http://www.atlassian.com/software/jira

Reply via email to