Fix a potential null pointer crashing issue