@Override
    public Object set(int index, Object element) {
        int size = super.size();
        if (index < 0) {
            index += size;
            if (index < 0) {
                // left join elem
                super.add(0, element);
                return null;
            }
            return super.set(
                    index, element
            );
        }

        if (index < size) {
            return super.set(
                    index, element
            );
        }

        // max expansion (size + 4096)
        if (index < size + 4096) {
            while (index-- != size) {
                super.add(null);
            }
            super.add(element);
        }
        return null;
    }
Replaces the element at the specified position with the specified element

<pre>{@code
   JSONArray array = new JSONArray();
   array.add(-1); // [-1]
   array.add(2); // [-1,2]
   array.set(0, 1); // [1,2]
   array.set(4, 3); // [1,2,null,null,3]
   array.set(-1, -1); // [1,2,null,null,-1]
   array.set(-2, -2); // [1,2,null,-2,-1]
   array.set(-6, -6); // [-6,1,2,null,-2,-1]
}</pre>

@param index index of the element to replace
@param element element to be stored at the specified position
@return the element previously at the specified position
@since 2.0.3
core/src/main/java/com/alibaba/fastjson2/JSONArray.java