Add the NULL caps check where it matters and also cover another case of potential NULL caps. Fixes #590030