add nullpointer check according to sona report