Skip to content

Commit 216beae

Browse files
committed
fix: add nullability check on safeFile variable to prevent crashes
1 parent ce4c23a commit 216beae

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @author Aitor Ballesteros Pavón
1111
* @author Jorge Aguado Recio
1212
*
13-
* Copyright (C) 2024 ownCloud GmbH.
13+
* Copyright (C) 2025 ownCloud GmbH.
1414
*
1515
* This program is free software: you can redistribute it and/or modify
1616
* it under the terms of the GNU General Public License version 2,
@@ -191,14 +191,16 @@ class PreviewImageFragment : FileFragment() {
191191
override fun onPrepareOptionsMenu(menu: Menu) {
192192
super.onPrepareOptionsMenu(menu)
193193
val safeFile = file
194-
// Update the file
195-
file = mContainerActivity.storageManager.getFileById(file.id ?: -1)
196-
val accountName = mContainerActivity.storageManager.account.name
197-
previewImageViewModel.filterMenuOptions(safeFile, accountName)
198-
199-
collectLatestLifecycleFlow(previewImageViewModel.menuOptions) { menuOptions ->
200-
val hasWritePermission = safeFile.hasWritePermission
201-
menu.filterMenuOptions(menuOptions, hasWritePermission)
194+
safeFile?.let {
195+
// Update the file
196+
file = mContainerActivity.storageManager.getFileById(it.id ?: -1)
197+
val accountName = mContainerActivity.storageManager.account.name
198+
previewImageViewModel.filterMenuOptions(it, accountName)
199+
200+
collectLatestLifecycleFlow(previewImageViewModel.menuOptions) { menuOptions ->
201+
val hasWritePermission = it.hasWritePermission
202+
menu.filterMenuOptions(menuOptions, hasWritePermission)
203+
}
202204
}
203205

204206
setRolesAccessibilityToMenuItems(menu)

0 commit comments

Comments
 (0)