Include a null check in castArray.