Fix NPEs in CastCompanionLibrary