Add null check (resolves PR16423)