List<Foo> results = null;
results = this.getResults();
if (results == null || results.size() == 0)
{
LOGGER.warn("results empty");
}
else
{
LOGGER.warn("results:" + results.toString());
}
The code above always produces the following output when getResults returns a null List.
results:[null]
I need to respond to this null scenario but don’t know how to catch it.
Everyone is correct that your list contains one null value. However, I don’t understand why it’s necessary to check to see if the first element is null. It looks more like you need to rethink what’s going on in
getResults()and not put null in the list. I mean, there’s no reason for us to assume there can’t more more nulls, or nulls sitting in between actual objects.