hardening on possible NPE due to null account/activity

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-10-09 08:15:32 +02:00
parent f321cedb24
commit 832e525f09
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 18 additions and 3 deletions

View file

@ -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);
}
});

View file

@ -895,4 +895,5 @@
<string name="download_latest_dev_version">Download latest dev version</string>
<string name="changelog_dev_version">Changelog dev version</string>
<string name="could_not_download_image">Could not download full image</string>
<string name="file_detail_activity_error">Error retrieving activities for file</string>
</resources>