public void removeField(int fieldNum) {
        // range check
        if (fieldNum < 0 || fieldNum >= this.numFields) {
            throw new IndexOutOfBoundsException();
        }
        int lastIndex = this.numFields - 1;

        if (fieldNum < lastIndex) {
            int len = lastIndex - fieldNum;
            System.arraycopy(this.offsets, fieldNum + 1, this.offsets, fieldNum, len);
            System.arraycopy(this.lengths, fieldNum + 1, this.lengths, fieldNum, len);
            System.arraycopy(this.readFields, fieldNum + 1, this.readFields, fieldNum, len);
            System.arraycopy(this.writeFields, fieldNum + 1, this.writeFields, fieldNum, len);
            markModified(fieldNum);
        }
        this.offsets[lastIndex] = NULL_INDICATOR_OFFSET;
        this.lengths[lastIndex] = 0;
        this.writeFields[lastIndex] = null;

        setNumFields(lastIndex);
    }
@Test
    void testRemoveField() {
        Record record;
        int oldLen;

        // Create filled record and remove field from the middle
        record = new Record(this.origVal1, this.origVal2);
        record.addField(this.origVal3);
        record.removeField(1);

        assertThat(record.getNumFields()).isEqualTo(2);

        StringValue recVal1 = record.getField(0, StringValue.class);
        IntValue recVal2 = record.getField(1, IntValue.class);

        assertThat(this.origVal1.getValue()).isEqualTo(recVal1.getValue());
        assertThat(this.origVal3.getValue()).isEqualTo(recVal2.getValue());

        record = this.generateFilledDenseRecord(100);

        // Remove field from the first position of the record
        oldLen = record.getNumFields();
        record.removeField(0);
        assertThat(oldLen - 1).isEqualTo(record.getNumFields());

        // Remove field from the end of the record
        oldLen = record.getNumFields();
        record.removeField(oldLen - 1);
        assertThat(oldLen - 1).isEqualTo(record.getNumFields());

        // Insert several random fields into the record
        record = this.generateFilledDenseRecord(100);

        for (int i = 0; i < 100; i++) {
            oldLen = record.getNumFields();
            int pos = this.rand.nextInt(record.getNumFields());
            record.removeField(pos);
            assertThat(oldLen - 1).isEqualTo(record.getNumFields());
        }
    }