diff --git a/changelog/unreleased/4738 b/changelog/unreleased/4738 new file mode 100644 index 00000000000..1b500d52d7b --- /dev/null +++ b/changelog/unreleased/4738 @@ -0,0 +1,10 @@ +Bugfix: Prevent NullPointerException when returning from external-file receive screen + +The share-into flow's `ReceiveExternalFilesActivity` forwarded a folder to +`ReceiveExternalFilesViewModel.refreshFolderUseCase` without guarding for null, +so any code path where `getCurrentDir()` resolved to `null` — such as leaving +the screen before the storage manager had loaded the parent folder — crashed +with a Kotlin platform-type NPE. The activity now skips the sync when the +folder cannot be resolved and logs the reason instead of crashing. + +https://github.com/owncloud/android/issues/4738 diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java index 2d0af9aeca0..c585e2f7ff2 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java @@ -628,6 +628,14 @@ public void onSavedCertificate() { } private void startSyncFolderOperation(OCFile folder) { + // getCurrentDir() and other callers can hand us a null folder when the + // storage manager cannot resolve the parent path yet; forwarding that + // to the Kotlin use case would trip the platform-type null check and + // crash as reported in issue #4738. + if (folder == null) { + Timber.w("startSyncFolderOperation called with a null folder; skipping sync"); + return; + } mSyncInProgress = true;