[Fix] loadSavedOperations IndexOutOfBoundsException (5.1.11 only issue)#2081
Merged
jinliu9508 merged 2 commits intomainfrom May 8, 2024
Merged
[Fix] loadSavedOperations IndexOutOfBoundsException (5.1.11 only issue)#2081jinliu9508 merged 2 commits intomainfrom
jinliu9508 merged 2 commits intomainfrom
Conversation
Test proving that loadSavedOperations can throw indexOutOfBoundsException. Real world scenario is this can happen if a few operations are added when the device is offline then the app is restarted.
jinliu9508
reviewed
May 8, 2024
Contributor
jinliu9508
left a comment
There was a problem hiding this comment.
The testing unit successfully thrown an IndexOutOfBoundException prior to the code change.

The test passed after the second commit.
However, I got a concurrent modification exception from a previous test unit. This is not stably reproducible though. It could be that calling queue.any from two different thread may interrupt each other if they happen to run at the same time.

Since things can be added to the queue before loadSavedOperations is called it has to account for duplicate entries. It did do this, however it was missing the logic to account for not advancing the index on duplicates so an out of bounds was possible. We solved the problem by only incrementing the index if it wasn't a duplicate, however this implementation has a future landmine. If something ever removes something from the queue that loadSavedOperations added and it is still executing index problems can still happen. This scenario never happens now, but a new feature to OperationRepo or a refactor could introduce the problem. A fast follow is recommend so this landmine isn't left here.
feafcda to
8aa83c5
Compare
Member
Author
|
Good catch! I have address the |
Member
Author
|
Tests failed on CI sometimes: Failure 1Failure 2These seem to be pre-existing flaky, not related to these changes. (so should be addressed in a different PR) |
jinliu9508
approved these changes
May 8, 2024
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.
Description
One Line Summary
Fixes
IndexOutOfBoundsexception thrown fromOperationRepo.loadSavedOperationsif app was opened offline, some operations done, and then the app is opened again.Details
Motivation
SDK needs to be stable, even if the device goes offline at any point.
Scope
Only affects
OperationRepo.loadSavedOperationsused on cold start of the app.Related
Fixes bug introduced in PR #2068 (released in 5.1.11)
Testing
Unit testing
Manual testing
Tested on an Android 14 emulator.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is