Is there a reason that the Iterables.isEmpty() is not null-safe (i.e.
it does not check for input being null)?
--
guava-...@googlegroups.com
http://guava-libraries.googlecode.com
http://groups.google.com/group/guava-discuss
unsubscribe: guava-discus...@googlegroups.com
This list is for discussion; for help, post to Stack Overflow instead:
http://stackoverflow.com/questions/ask
Use the tag "guava".
I see your point.
Although, for example Spring framework's internal CollectionUtils
still uses the 'old' is-null-or-empty logic. i think it just saves you
an ugly null check every time, plus 99% of time (if not always) null
Collection semantically means the same as empty Collection (means no
data) in your business logic.
but hey, it's your project at the end of the day ;-)
if (xs != null)
for (Object x : xs)
..
This thing becomes like a virus: eventually, this is what your staff
will write, if they are faced with a lot of nulls meaning empty. Besides
adding an extra level of identation, which is problematic in and of
itself, this increases the McCabe complexity of just about every file in
your codebase, and hence, your test footprint. Had an employee that did
this. Made him go back and change it. Not Recommended.
I passionately hate null checks. Having once waded for days through
someone else's (extremely) null-check-bloated code, I am forever
traumatized.
--
Johan Van den Neste
All flamebait aside, +1 for applying Objects.firstNonNull at the
source to rid your code of null pointers.
bp
-1 for this. I agree, I treat them as independent values. null being
unknown and empty as known empty.