fix(ui): prevent NPE and memory leaks in FileDetailActivitiesFragment#16465
Merged
alperozturk96 merged 1 commit intomasterfrom Feb 9, 2026
Merged
fix(ui): prevent NPE and memory leaks in FileDetailActivitiesFragment#16465alperozturk96 merged 1 commit intomasterfrom
alperozturk96 merged 1 commit intomasterfrom
Conversation
- Cancel SubmitCommentTask in onDestroyView to prevent post-destruction callbacks - Wrap callback in WeakReference to allow garbage collection - Add lifecycle checks (RESUMED state) before accessing binding in callbacks - Add defensive null checks for binding throughout fragment methods - Check isCancelled() in AsyncTask to prevent unnecessary work after cancellation Fixes crashes when fragment view is destroyed while comment submission is pending. Fixes #9351 Signed-off-by: Josh <josh.t.richards@gmail.com>
7f2e929 to
f971397
Compare
alperozturk96
approved these changes
Feb 9, 2026
Collaborator
alperozturk96
left a comment
There was a problem hiding this comment.
Hello
Thank you for the PR. Submitting comments is working; however, displaying them is not. This issue is out of scope for the current PR, as the master branch exhibits the same behavior.
|
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/16465.apk |
|
blue-Light-Screenshot test failed, but no output was generated. Maybe a preliminary stage failed. |
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.

Problem
SubmitCommentTaskcallbacks could execute afteronDestroyView(), causing NPE crashes when accessing null binding. AndAsyncTaskwas never cancelled, creating possible memory leaks.Fixes #93511
Related prior PR context: #7210
Solution
submitCommentTaskfield to track running taskonDestroyView()and before starting new submissionsisCancelled()checks indoInBackground()andonPostExecute()WeakReference<>inSubmitCommentTaskcallback = nullinonDestroyView()binding != null && Lifecycle.State.RESUMEDcheck inonSuccess()getView() != null && isAdded()check inonError()binding != nullchecks in:submitComment(),setLoadingMessage(),setLoadingMessageEmpty(),populateList(),setInfoContent(),hideRefreshLayoutLoader(),avatarGenerated()Files Changed
FileDetailActivitiesFragment.java: Fixed callback lifecycle, added AsyncTask cancellation, added null safety checksTesting
Note
Footnotes
https://github.com/nextcloud/android/blob/695079ef957a86523e6f67c5bc82ef0929c61200/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java#L171-L174 ↩