commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: [lang] proposal to add a couple of methods to StringUtils
Date Fri, 27 Sep 2002 18:53:15 GMT

Btw...
can you not just use:

StringUtils.defaultString(""+obj) for now?

On Fri, 27 Sep 2002, Steven Caswell wrote:

> I'd like to add the following methods to StringUtils:
>
> String defaultString(Object obj) - behaves the same as
> defaultString(String), invoking toString() on the obj to return the
> string, or blank if obj is null
> String defaultString(Object obj, String defaultString) - same as
> defaultString(String, String), invoking toString() on the obj to return
> the string, or the defaultString value if obj is null
>
> A specific use case: I do lots of debug logging, many times logging
> results from various method calls, some of which may not be null-safe.
> In cases where a method return could be null, I need to check the return
> for null and replace what would be logged with some placeholder string
> (i.e., "(null)". So the following code would be replace:
>
> debugLog.debug( "MyClass.myMethod() = " + ((MyClass.myMethod() == null)
> ? "(null)" : MyClass.myMethod().toString() + ")" );
>
> with
>
> debugLog.info( "MyClass.myMethod() = " +
> StringUtils.defaultString(MyClass.myMethod(), "(null"));
>
> I could use StringUtils.defaultString now if the result were a string,
> but for non-String objects where is no equivalent. I don't want to use
> StringUtils.defaultString(MyClass.myMethod().toString(), "(null)")
> because I'll get an NPE on the .toString() and defaultString will never
> have a chance.
>
> Would this hold up the imminent release? If so I'll defer to afterward.
>
> Steven Caswell
> steven@caswell.name
>
>
>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message