IJPL 173473: fix ArrayIndexOutOfBoundsException when using ContainerUtil.concat() #2893
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
The method ContainerUtil.concat(list1, list2) works fine with immutable lists. However, if the lists are modified concurrently, iteration may fail. see: IJPL-173473
This fix contains a unit test
ContainerUtilTest.testConcatenatedDynamicListsAreIterable
to disclose the problem.Surprisingly it does not indicate any problem, if you start joining two empty lists. This is, because the size of the composed list is calculated in advance and never change. So, while an underlying
List
is growing, the composedList
just does nothing. But I think this is also not the expected behavior. But if anyList
shrinks, the concatenatedList
throws anIndexOutOfBoundsException
.To fix this, I introduced an
iterator()
method for the concatenatedList
to get the actual elements from both lists.Other utility methods here, using a straightforward
new AbstractList<T>
, may suffer from the same problem but are not fixed so far.