commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben Speakmon (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LANG-360) Why does appendIdentityToString return null?
Date Tue, 30 Oct 2007 07:36:50 GMT

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

Ben Speakmon commented on LANG-360:
-----------------------------------

It's unfortunate that the API here forces the user to null-protect his parameters to it. I
think it's clear that the better choice would have been to simply append "null", since that
is the toString() value of the null reference according to the JLS. That said, it is documented
to work the way it does, and that makes it not wrong but simply annoying.

+1 to Paul's idea and having a similarly named method with another parameter with a default
value. Maybe we should also deprecate the current one for 2.4 with a warning explaining this
problem.

> 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.


Mime
View raw message