Add some NPE guards for in inspections.

Closes #1040