Avoid null point exception in string comparator