nextcloud / nextcloud/android

Switching accounts deletes synced folder + NPE `ReceiveExternalFilesActivity.onCreateOptionsMenu canWrite()`

Open
#13,348 1 comment 0 reactions 0 assignees View on GitHub
bug feature: app-to-app sharing feature: authentication feature: sync performance: NPE :no_entry_sign: stable-3.29
Dominant language
Kotlin
Stars
5.6k
Forks
2k
Avg merge
2d 18h
Merged PRs (30d)
92

Description

### ⚠️ Before posting ⚠️

- [X] This is a **bug**, not a question or an enhancement.
- [X] I've [searched for similar issues](https://github.com/nextcloud/android/issues) and didn't find a duplicate.
- [X] I've written a clear and descriptive title for this issue, not just "Bug" or "Crash".
- [X] I agree to follow Nextcloud's [Code of Conduct](https://nextcloud.com/contribute/code-of-conduct/).

### Steps to reproduce

1. Share a file to the Nextcloud app from the share sheet
2. Go to a folder that has some locally synced files on Account1
3. Click on Switch account in the top-right menu
4. Switch to Account2
5. Account2 will not show up immediately, instead the current folder of Account1 is still shown. However, image previews are missing. The locally synced files in the folder are still on the file system.
6. Click on the back arrow in the top left.
7. The whole folder that was open including its files are deleted on the device.

### Expected behaviour

Clear the UI before switching the account in the backend logic or show some loading screen (or at the very least, don't delete local folders)

### Actual behaviour

Nextcloud app deletes the local folder of Account1 including its files (I assume that the backend logic of the app detects that the folder from Account1 does not exist in Account2 and therefore it deletes it locally). At some point it will either show the content of Account2 or crash before that with a NullPointerException if you click on a folder that exists only on Account1 (see below for NPE).

### Android version

14

### Device brand and model

Pixel 6 Pro

### Stock or custom OS?

Custom (explain in "additional information")

### Nextcloud android app version

3.29.1-fdroid

### Nextcloud server version

29.0.4

### Using a reverse proxy?

No

### Android logs

_No response_

### Server error logs

_No response_

### Additional information

_No response_

### Cause of error
```java
Exception in thread "main" java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.owncloud.android.datamodel.OCFile.canWrite()' on a null object reference
at com.owncloud.android.ui.activity.ReceiveExternalFilesActivity.onCreateOptionsMenu(ReceiveExternalFilesActivity.java:1014)
at android.app.Activity.onCreatePanelMenu(Activity.java:4595)
at androidx.activity.ComponentActivity.onCreatePanelMenu(ComponentActivity.java:520)
at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:95)
at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.onCreatePanelMenu(AppCompatDelegateImpl.java:3429)
at androidx.appcompat.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:458)
at androidx.appcompat.app.ToolbarActionBar$1.run(ToolbarActionBar.java:58)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1406)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1415)
at android.view.Choreographer.doCallbacks(Choreographer.java:1015)
at android.view.Choreographer.doFrame(Choreographer.java:941)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1389)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8592)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.