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

jogi edited comment on LANG-360 at 10/29/07 11:54 PM:
------------------------------------------------------------------

Yes, this behavior is in sync with the javadoc. That's where I found it first. 
But that did not mean that it is a good behavior.

I like to vote against a second method with a default value. Who needs a 
default value, when debugging an object? (If this bean is null, log another 
one?) A method appendIdentityToStringNullSave would be better, but a little 
ugly.

>> Almost all of Commons Lang behavior returns null where possible for a null 
>> source parameter.  <<

Hm, I don't think so. And evan if it would be: Returning null, if the 
StringBuffer is null could be argued, but returning null if the second value is 
null is definitly a bad behavior. Remember this:
   appendIdentityToString(new StringBuffer(), null)  
Would you expect this to return null? But this does not return null:
   appendIdentityToString(null, new Object())
Really confusing.

      was (Author: jogi):
    Yes, this behavior is in sync with the javadoc. That's where I found it 
first. But that did not mean that it is a good behavior.

I like to vote against a second method with a default value. Who needs a 
default value, when debugging an object? (If this bean is null, log another 
one?) A method appendIdentityToStringNullSave would be better, but a little 
ugly.

>> Almost all of Commons Lang behavior returns null where possible for a null 
>> source parameter.  <<

Hm, I don't think so. And evan if it would be: Returning null, if the 
StringBuffer is null could be argued, but returning null if the second value is 
null is definitly a bad behavior. Remember this:   appendIdentityToString(new 
StringBuffer(), null)   Would you expect this to return null? But this does not 
return null:    appendIdentityToString(null, new Object())   Really confusing.
  
> Why does appendIdentityToString return null?
> --------------------------------------------
>
>                 Key: LANG-360
>                 URL: https://issues.apache.org/jira/browse/LANG-360
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Jörg Gottschling
>             Fix For: 2.4
>
>
> ObjectUtils is designed to handle null imputs gracefully. But 
> ObjectUtils.appendIdentityToString does not. It returns null unnessecary if 
> you pass null als second parameter (the object to get the identity from). For 
> example appendIdentityToString(new StringBuffer(), null) will return null! 
> Which is an uncommen behaviour. Think about code like this:
> ObjectUtils.appendIdentityToString(buffer, param1)
>                     .appendIdentityToString(buffer, param2)
>                     .appendIdentityToString(buffer, param3);
> This will cause an NPE if param1 or param2 ist null. There may be other code 
> where a NPE will not happen, but the code is used for debugging and there 
> will be an unexpected or wrong output.
> So you shoul return the StringBuffer which is passed in or a new one if null. 
> The harder question is what to do with the object. I think we should append 
> "null" to the StringBuffer, because this is what I would expect and what the 
> passed reference is.

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

Reply via email to