On Thursday 26 September 2002 04:54 am, Stephen Colebourne wrote:
> My view is that one of the main advantages of StringUtils is to avoid NPEs.
> I actually thought that we'd been through all the methods and ensured that
> none of them did throw a NPE.
>
I think that's overkill. You have to decide what to do with null, and often
the right thing to do is throw an NPE. Treating null as "" generally isn't a
good idea. If that's what you want, using StringUtils.clean() in the calling
code works.
> As I sugested the method initially, I looked at what my own implementation
> of this does and what my needs are. Basically I find the current
> implementation fine:
> containsOnly("", anything but null) returns true
> containsOnly(null, anything) returns false
>
Reasonable in this case. Although I'm not entirely convinced that
containsOnly(string, null) shouldn't be an exception. If I were writing it
from scratch, I'd probably leave it as one, but current clients now have
reasonable expectation that it won't.
IOW, I'm not suggesting changing anything, just clarifying documentation.
Still, where we're writing methods that would naturally be part of the String
API, ie instead of StringUtils.someMethod(string), we would have
string.someMethod(), not throwing an NPE on someMethod(null) breaks the
symmetry.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>