I think we can move this check up further, can't we? From what I can't see it doesn't depend on the ByteArray being created, so we might as well check before doing that then.