-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix crash during text file creation #5442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash during text file creation #5442
Conversation
f24de1f to
080d5d3
Compare
| if (chooseTemplateDialogFragmentWeakReference.get() != null) { | ||
| FileDataStorageManager storageManager = new FileDataStorageManager( | ||
| user.toPlatformAccount(), | ||
| chooseTemplateDialogFragmentWeakReference.get().requireContext().getContentResolver()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty common error I see. Both activities and fragments are passed as weak references to avoid leaks, but in case of fragment we must check if it has been detached.
Codecov Report
@@ Coverage Diff @@
## master #5442 +/- ##
============================================
- Coverage 21.78% 20.92% -0.87%
Complexity 3 3
============================================
Files 398 398
Lines 33326 33325 -1
Branches 4674 4675 +1
============================================
- Hits 7259 6972 -287
- Misses 24888 25222 +334
+ Partials 1179 1131 -48
|
|
IT test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/12607-IT |
tobiasKaminsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To discuss
| } | ||
|
|
||
| final Context context = fragment.getContext(); | ||
| if (context == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also "isAdded" or "isDetached", which we can use, or?
getContext is: return mHost == null ? null : mHost.getContext()
isAdded is: return mHost != null && mAdded
So isAdded might even the more extensive check, or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you can use that, as it calls @NonNull FragmentHostCallback.getContext().
However, because subsequent call to getContext() is not @NonNull, linter will still complain that you use nullable Context, encouraging another, rendundant check.
Because the action run here is not related to UI elements displayed on the screen, we can rely on Context check without risk of any glitches.
Android API is not a pinnacle of software engineering, and Fragment API is of particularly bad reputation in general. I'd say that looking for an inspiration for best practices in the official documentation is rather risky endeavour. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.
Then let us keep it this way 👍
9c9541c to
7583fab
Compare
|
Thanks for finding and fixing this bug 🎉 |
|
IT test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/12687-IT |
|
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12692.apk |
|
IT test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/12692-IT |
AndyScherzinger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
Needs a Rebase 😎
Fixes #5330 Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com> Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
829b307 to
0977c37
Compare
|
Issues
======
- Added 1
See the complete overview on Codacy |
| return ""; | ||
| } | ||
|
|
||
| OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12708.apk |
Codacy347Lint
SpotBugs (new)
SpotBugs (master)
|
|
Screenshot test failed, but no output was generated. Maybe a preliminary stage failed. |
2b26a51 Merge remote-tracking branch 'origin/master' into dev 4616b0d Merge pull request #5447 from nextcloud/ezaquarii/migrate-jobs-to-new-user-model 20b910a Merge pull request #5442 from nextcloud/ezaquarii/fix-crash-on-text-file-creation 0977c37 Fix crash during text file creation 5c74f2b [tx-robot] updated from transifex 27fabe7 [tx-robot] updated from transifex 6029548 daily dev 20200215


Fixes #5330
Signed-off-by: Chris Narkiewicz hello@ezaquarii.com
Testing
Manual test only. Create a text file, invoking template chooser dialog.