Add null check for avoiding std::string crash