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.
Merge pull request #161 from WangTaoTheTonic/master

Check if the List is null before using it