Fix a possible NPE in if