ensure ReentrantLock is unlocked after being locked, and on same thread #2759
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 #2432
The reentrant locks were engaged unconditionally on the then-main thread but the async task was only started conditionally. The unlocking of the locks was managed by the async task.
This lead to two issues:
if the condition checked for in
initializeFileDirsPaths
was already met, the locks were engaged but never unlocked. Any subsequent attempt to lock would just block execution forever.(hypothetical, not tested:) the thread id of the app's main thread when the async task finished and thus calls
onPostExecute
oronCancel
on that thread may differ from the thread id of the app's main thread wheninitializeFileDirsPaths
was invoked: E.g. if the app was sent to background and effectively re-started later by the Android system. However, reentrant locks require to be locked/unlocked on the same thread, otherwise they will throw anIllegalMonitorStateException
. The previous mechanism could not ensure this.In any case, I am pretty sure either of these two issues is the cause for #2432.