`ContentPath` class maintains a variable `index` that has the next available index to write path to. In fact to add a path we did `path[index++] = name;` so we write at index position and increment it afterwards. To remove last path we are doing `path[index--] = null;` this would set to null the next available index position (that is already null) and later subtract 1 from index. This was masked by the fact that when retrieving a path we loop from 0 up until `i < index`, therefore masking the fact that there could have being 'removed' but not null path existing at `index`.

_Originally posted by @piergm in https://github.com/elastic/elasticsearch/pull/97972#discussion_r1287055169_
            
server/src/main/java/org/elasticsearch/index/mapper/ContentPath.java
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */
package org.elasticsearch.index.mapper;
public final class ContentPath {
    private static final char DELIMITER = '.';
    private final StringBuilder sb;
    private int index = 0;
    private String[] path = new String[10];
    private boolean withinLeafObject = false;
    public ContentPath() {
        this.sb = new StringBuilder();
    }
    public void add(String name) {
        path[index++] = name;
        if (index == path.length) {