Possible dereference after null - move the if() to include all checks (cherry picked from commit e6316eb4)