fix npe crash by adding null check