private void checkArrayLength(int length, int offset, int arrayLength) {
        if (length < 0 || length + offset > arrayLength) {
            throw new IllegalArgumentException("Invalid length " + length);
        }
    }