[PLAT-6346] Check all array elements before casting

Reviewed-by: Vince Lam