Remove unsafe casts to union types

Test: NFC sanity
Change-Id: I126dd9dc856a8b1d11ed4031e7dabf086281200d
18 files changed