Fix IndexOutOfBoundsException when reattaching reordered list with cache.collections=false#534
Open
jasper-vandemalle wants to merge 1 commit intodatanucleus:masterfrom
Conversation
3222a8c to
178bd9f
Compare
…che.collections=false (datanucleus#526)
178bd9f to
4430d47
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #526.
If you detach an entity with a List, insert elements anywhere but the end, then reattach with
datanucleus.cache.collections=false, you get anIndexOutOfBoundsExceptionduring the reorder phase inSCOUtils.updateListWithListElements().Root cause is two things fighting each other:
The backed List/ArrayList/Vector
set(int, E, boolean)methods calldelegate.set()without loading the delegate first whenuseCache=false. Empty delegate, instant crash.The reorder phase reads positions via
list.get(position)(hits the backing store when uncached) but writes viaset()(hits the delegate). After queued updates these two views disagree, so you get garbage.The fix:
set()now callsloadFromStore()before touching the delegate. This is already guarded by!isCacheLoadedso it's a no-op once loaded. For the reorder phase, I snapshot the current list order via iteration before comparing, so we're not reading from two different sources mid-loop.Integration test in companion PR: datanucleus/tests#92