Don't directly dereference getAs<> casts to avoid potential null dereferences. NFCI.

Replace with castAs<> which asserts the cast is valid.

Fixes a number of static analyzer warnings.

GitOrigin-RevId: 2901dc7575873ed4bdfa1d7a0e79020e7a9ffb3d
12 files changed