From 832e525f091d1f14e7bd28c16cbcc1045587b914 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 9 Oct 2019 08:15:32 +0200 Subject: [PATCH] hardening on possible NPE due to null account/activity Signed-off-by: tobiasKaminsky --- .../FileDetailActivitiesFragment.java | 20 ++++++++++++++++--- src/main/res/values/strings.xml | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java index 27ca327741..60886c3f7f 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java @@ -292,13 +292,27 @@ public class FileDetailActivitiesFragment extends Fragment implements * @param lastGiven int; -1 to disable */ private void fetchAndSetData(int lastGiven) { - final Account currentAccount = accountManager.getCurrentAccount(); - final Context context = MainApp.getAppContext(); final FragmentActivity activity = getActivity(); + if (activity == null) { + Log_OC.e(this, "Activity is null, aborting!"); + return; + } + final SwipeRefreshLayout empty = swipeEmptyListRefreshLayout; final SwipeRefreshLayout list = swipeListRefreshLayout; + final Account currentAccount = accountManager.getCurrentAccount(); + if (currentAccount == null) { + activity.runOnUiThread(() -> { + setEmptyContent(getString(R.string.common_error), getString(R.string.file_detail_activity_error)); + list.setVisibility(View.GONE); + empty.setVisibility(View.VISIBLE); + }); + return; + } + + final Context context = MainApp.getAppContext(); Thread t = new Thread(() -> { OwnCloudAccount ocAccount; @@ -372,7 +386,7 @@ public class FileDetailActivitiesFragment extends Fragment implements hideRefreshLayoutLoader(activity); } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException | IOException | - OperationCanceledException | AuthenticatorException e) { + OperationCanceledException | AuthenticatorException | NullPointerException e) { Log_OC.e(TAG, "Error fetching file details activities", e); } }); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 15d43ffff3..1ec925a54a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -895,4 +895,5 @@ Download latest dev version Changelog dev version Could not download full image + Error retrieving activities for file