From 91cfb0cfa2c0901b9e633ae1ebb63864cd3ce2c5 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Thu, 28 Sep 2023 08:28:08 +0100 Subject: [PATCH] Fix cr --- changelog/unreleased/4170 | 4 ++-- .../android/data/files/repository/OCFileRepository.kt | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/changelog/unreleased/4170 b/changelog/unreleased/4170 index 55d12671faa..e7ad28c99a7 100644 --- a/changelog/unreleased/4170 +++ b/changelog/unreleased/4170 @@ -1,6 +1,6 @@ -Bugfix: Null pointer exception have been avoided +Bugfix: Some Null Pointer Exceptions avoided -in the detail screen as elsewhere the app has been prevented from crashing when a null is found. +in the detail screen, in the main file list ViewModel and in the OCFile repository the app has been prevented from crashing when a null is found. https://github.com/owncloud/android/issues/4158 https://github.com/owncloud/android/pull/4170 diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt index bd4d9b5df34..fbb94a734cb 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt @@ -168,10 +168,14 @@ class OCFileRepository( val personalSpace = localSpacesDataSource.getPersonalSpaceForAccount(owner) if (personalSpace == null) { val legacyRootFolder = localFileDataSource.getFileByRemotePath(remotePath = ROOT_PATH, owner = owner, spaceId = null) - return legacyRootFolder ?: throw IllegalStateException("LegacyRootFolder not found") + try { + return legacyRootFolder ?: throw IllegalStateException("LegacyRootFolder not found") + } catch (e: IllegalStateException) { + Timber.i("There was an error: $e") + } } // TODO: Retrieving the root folders should return a non nullable. If they don't exist yet, they are created and returned. Remove nullability - val personalRootFolder = localFileDataSource.getFileByRemotePath(remotePath = ROOT_PATH, owner = owner, spaceId = personalSpace.root.id) + val personalRootFolder = localFileDataSource.getFileByRemotePath(remotePath = ROOT_PATH, owner = owner, spaceId = personalSpace?.root?.id) return personalRootFolder!! }