Add defensive code to avoid crash.

Probably not the best fix as it is not on the root cause.