commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <>
Subject [jira] Commented: (LANG-360) Why does appendIdentityToString return null?
Date Mon, 05 Nov 2007 15:58:50 GMT


Henri Yandell commented on LANG-360:

The problem with the method lies with the automagical creation. Passing in null should not
lead to a StringBuffer being created and then returned - the user should be responsible for
their parameters. StringBuffer methods should have void return types. 

The best way to solve that is to deprecate the old StringBuffer method and add a new method

* public static void identityToString(StringBuffer, Object) 

One that throws an NPE if the first param is null.

The second question is what to do in the case of Object being null. Currently the String variant
returns null. The new StringBuffer variant could either append "null", "", or throw an NPE.
The old library was effectively appending "", so that's the current behaviour. I can see value
in all three options, so suggest we stick with the empty String option - ie) nothing happens
to the buffer. 

> Why does appendIdentityToString return null?
> --------------------------------------------
>                 Key: LANG-360
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Jörg Gottschling
>             Fix For: 2.4
>         Attachments: LANG-360.patch
> 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.

View raw message