Skip to content

Conversation

@ezaquarii
Copy link
Collaborator

@ezaquarii ezaquarii commented Feb 10, 2020

Fixes #5330

Signed-off-by: Chris Narkiewicz hello@ezaquarii.com

Testing

Manual test only. Create a text file, invoking template chooser dialog.

@ezaquarii ezaquarii force-pushed the ezaquarii/fix-crash-on-text-file-creation branch from f24de1f to 080d5d3 Compare February 10, 2020 06:53
if (chooseTemplateDialogFragmentWeakReference.get() != null) {
FileDataStorageManager storageManager = new FileDataStorageManager(
user.toPlatformAccount(),
chooseTemplateDialogFragmentWeakReference.get().requireContext().getContentResolver());
Copy link
Collaborator Author

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
Copy link

codecov bot commented Feb 10, 2020

Codecov Report

Merging #5442 into master will decrease coverage by 0.86%.
The diff coverage is 0%.

@@             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
Impacted Files Coverage Δ Complexity Δ
...ndroid/ui/dialog/ChooseTemplateDialogFragment.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...cloud/android/utils/svg/SvgDrawableTranscoder.java 0% <0%> (-100%) 0% <0%> (ø)
.../owncloud/android/datamodel/VirtualFolderType.java 0% <0%> (-100%) 0% <0%> (ø)
...va/com/owncloud/android/ui/events/SearchEvent.java 0% <0%> (-60%) 0% <0%> (ø)
...ava/com/owncloud/android/utils/svg/SvgDecoder.java 0% <0%> (-50%) 0% <0%> (ø)
...ncloud/android/ui/adapter/ActivityListAdapter.java 12% <0%> (-49.34%) 0% <0%> (ø)
...loud/android/utils/svg/SvgSoftwareLayerSetter.java 0% <0%> (-44.45%) 0% <0%> (ø)
...m/nextcloud/client/account/UserAccountManager.java 0% <0%> (-33.34%) 0% <0%> (ø)
...d/android/operations/GetCapabilitiesOperation.java 75% <0%> (-12.5%) 0% <0%> (ø)
...ain/java/com/owncloud/android/ui/TextDrawable.java 74.07% <0%> (-11.12%) 0% <0%> (ø)
... and 21 more

@nextcloud-android-bot
Copy link
Collaborator

Copy link
Member

@tobiasKaminsky tobiasKaminsky left a 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) {
Copy link
Member

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?

Copy link
Collaborator Author

@ezaquarii ezaquarii Feb 13, 2020

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. :)

Copy link
Member

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 👍

@ezaquarii ezaquarii force-pushed the ezaquarii/fix-crash-on-text-file-creation branch 2 times, most recently from 9c9541c to 7583fab Compare February 13, 2020 22:34
@tobiasKaminsky
Copy link
Member

Thanks for finding and fixing this bug 🎉

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12692.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Copy link
Member

@AndyScherzinger AndyScherzinger left a 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>
@tobiasKaminsky tobiasKaminsky force-pushed the ezaquarii/fix-crash-on-text-file-creation branch from 829b307 to 0977c37 Compare February 17, 2020 08:30
@nextcloud-android-bot
Copy link
Collaborator

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 1
           

See the complete overview on Codacy

return "";
}

OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12708.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

347

Lint

TypemasterPR
Warnings7777
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings71
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings78
Security Warnings45
Dodgy code Warnings138
Total385

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings71
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings78
Security Warnings45
Dodgy code Warnings139
Total386

@nextcloud-android-bot
Copy link
Collaborator

Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@nextcloud-android-bot
Copy link
Collaborator

@tobiasKaminsky tobiasKaminsky merged commit 20b910a into master Feb 17, 2020
@delete-merged-branch delete-merged-branch bot deleted the ezaquarii/fix-crash-on-text-file-creation branch February 17, 2020 09:34
@AndyScherzinger AndyScherzinger added this to the Nextcloud App 3.11.0 milestone Feb 17, 2020
tobiasKaminsky added a commit that referenced this pull request Feb 18, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crashes on text file creation

5 participants