Skip to content

fix: guard bottom-nav against NPE when no account is set - #5012

Merged
jesmrec merged 4 commits into
owncloud:masterfrom
ibrahim-iqbal:fix/4998-nullable-storage-manager-npe
Oct 19, 2026
Merged

jesmrec merged 4 commits into
owncloud:masterfrom
ibrahim-iqbal:fix/4998-nullable-storage-manager-npe

Conversation

@ibrahim-iqbal

Copy link
Copy Markdown
Contributor

Fixes #4998

Crash

java.lang.NullPointerException
  at com.owncloud.android.datamodel.FileDataStorageManager.<init>
  at com.owncloud.android.ui.activity.BaseActivity.getStorageManager
  at com.owncloud.android.ui.activity.FileDisplayActivity.navigateTo
  at com.owncloud.android.ui.activity.FileDisplayActivity.navigateToOption
  at com.owncloud.android.ui.activity.DrawerActivity.bottomBarNavigationTo

Root cause

FileDataStorageManager's constructor takes a non-null Account. BaseActivity.getStorageManager() has:

public FileDataStorageManager getStorageManager() {
    if (mStorageManager == null) {
        if (getAccount() == null) {
            swapToDefaultAccount();
        }
        return mStorageManager = new FileDataStorageManager(getAccount());
    }
    ...
}

swapToDefaultAccount() only sets mCurrentAccount when a valid account is found; when none exists (e.g. the last account was just removed from the device, or the app reaches this state before onboarding), it instead calls createAccount(true) to launch the setup flow and returns with the account still null. The very next line then passes that still-null getAccount() straight into the non-null Kotlin constructor → NPE.

A bottom navigation bar click (DrawerActivity.bottomBarNavigationTo → navigateToOption → FileDisplayActivity.navigateTo → getStorageManager()) can land in exactly that window, while the account-setup activity is launching but hasn't taken focus yet.

Fix

Added a navigateToOptionIfAccountReady wrapper in DrawerActivity that no-ops when account == null, used at the three navigateToOption call sites in bottomBarNavigationTo (All Files, Spaces, Available Offline, Shared by Link). The account-setup screen is already on its way, so there's nothing useful to navigate to — silently skipping is correct instead of crashing. The Uploads nav item is untouched since it launches UploadListActivity directly and never touches the storage manager.

This doesn't change getStorageManager()'s own (non-null) contract or any other caller — it stops the crash at the one site where a UI click could race the account-setup redirect.

Testing

  • ./gradlew :owncloudApp:compileOriginalDebugKotlin — compiles clean, no errors.
  • No device available to reproduce the exact "last account removed" state; the fix is a direct, minimal guard against the documented null read in the stack trace.

AI assistance

Drafted with AI assistance; I reviewed every line and traced the full call chain from the stack trace in the issue to the root cause in BaseActivity.getStorageManager().

🤖 Generated with Claude Code

@joragua

joragua commented Oct 13, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution @ibrahim-iqbal! 🙌🏻

Some notes before the CR:

  1. Every commit must be GPG/PGP signed and include a Signed-off-by line. Use the command: git commit -s -S -m "..."for that. Unfortunately, we won't be able to merge the PR until all commits are properly signed.

  2. Could you add a new commit (chore: add calens file) including all the changelog information? Please don't forget to read the TEMPLATE.md before adding it.

Let us know if you have any doubts and we will help you! 😄

@ibrahim-iqbal
ibrahim-iqbal force-pushed the fix/4998-nullable-storage-manager-npe branch from 53794f7 to a1f2bfe Compare October 13, 2026 12:03
@ibrahim-iqbal

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review! Both done:

  1. Both commits are now GPG-signed with a Signed-off-by line.
  2. Added the changelog entry at changelog/unreleased/4998.

Ready for another look.

@joragua joragua left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @ibrahim-iqbal! Some comments about your PR

Comment thread changelog/unreleased/4998 Outdated
Comment thread changelog/unreleased/4998 Outdated
Comment thread owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt Outdated
Comment thread owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt Outdated
@ibrahim-iqbal
ibrahim-iqbal force-pushed the fix/4998-nullable-storage-manager-npe branch from a1f2bfe to a423e79 Compare October 14, 2026 12:19
@ibrahim-iqbal

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @joragua! All addressed:

  1. Renamed the calens file to 5012 and reworded the description per your suggestion - amended into the same chore: add calens file commit rather than adding a new one.
  2. Removed the AI-generated doc comment on navigateToOptionIfAccountReady and inlined the null-check at the top of bottomBarNavigationTo as suggested, in a separate commit.

Ready for another look.

@joragua

joragua commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

@ibrahim-iqbal just check the comment above and it's ready

EDIT: I mean, this comment should be removed

// #4998: account can be null here if the last account was just removed and
// BaseActivity.swapToDefaultAccount() is already launching account setup;
// navigateToOption() would NPE on getStorageManager() in that case.

@ibrahim-iqbal

Copy link
Copy Markdown
Contributor Author

Removed, thanks — missed that one, good catch.

@joragua joragua left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 💯

The branch now needs to be rebased against master before it can be merged. Please let us know if you have any problems and we will help you!

@jesmrec

jesmrec commented Oct 19, 2026

Copy link
Copy Markdown
Member

@ibrahim-iqbal please rebase the branch and it will be straight merged. Thanks!

When the last account is removed (or no account exists yet),
BaseActivity.swapToDefaultAccount() launches the account-setup flow
but leaves the account null for the rest of the activity's lifecycle.
A bottom-nav click in that window still called navigateToOption(),
which eventually constructs FileDataStorageManager(account) and NPEs
on the null account.

Guard the three navigateToOption() call sites in
DrawerActivity.bottomBarNavigationTo with a null-account check — the
setup screen is already launching, so there's nothing to navigate to.
The Uploads nav item is untouched since it never touches the storage
manager.

Signed-off-by: ibrahim-iqbal <ibrahim-iqbal@users.noreply.github.com>
Signed-off-by: ibrahim-iqbal <ibrahim-iqbal@users.noreply.github.com>
Per review: moved the account==null check to the top of
bottomBarNavigationTo itself instead of a separate
navigateToOptionIfAccountReady wrapper, and replaced the long
AI-generated doc comment with a one-line note matching the file's
existing comment style.

Signed-off-by: ibrahim-iqbal <ibrahim-iqbal@users.noreply.github.com>
…onTo

Same category as the earlier removed comment on navigateToOptionIfAccountReady -
the guard clause is self-explanatory, the comment restated it.

Signed-off-by: ibrahim-iqbal <ibrahim-iqbal@users.noreply.github.com>
@ibrahim-iqbal
ibrahim-iqbal force-pushed the fix/4998-nullable-storage-manager-npe branch from 5bb8a3c to 8f500b1 Compare October 19, 2026 07:27
@ibrahim-iqbal

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (8f500b1). All commits remain GPG-signed with Signed-off-by. Ready to merge.

@jesmrec
jesmrec merged commit 9a5dc1c into owncloud:master Oct 19, 2026
7 checks passed
@jesmrec

jesmrec commented Oct 19, 2026

Copy link
Copy Markdown
Member

Merged! thanks again @ibrahim-iqbal!! your contribution will be part of 5.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] FileDataStorageManager crash in Play Console

3 participants