Check if the List is null before using it

The variable "List<NetAddress> locations" might be null, so we should
check it before using its method size() in case that it throws a
NullPointerException.