My professor was discussing issues that can arise when multiple threads concurrently access the same data field of an object with the following code
@Override
public void run() {
// main for a thread
for (int i = 0; i < 1_000_000; i++) {
list.add(i);
}
}
the code threw an IndexOutOfBoundsException: Index 13 out of bounds for length 10 and the explanation he gave is that the 2 threads hit the max capacity and then thread1 would add enough to trigger a second resize which then got overridden by thread2's first resize making it smaller than thread1's insertion point. That would make sense for most IndexOutOfBoundsExceptions, but isn't the ArrayList's default size set to 10, so in this case thread2 can't resize down to 10 and some other issue caused the IndexOutOfBoundsException?
How did the size get downsized to 10?