Skip to content

Conversation

@alexknop
Copy link
Collaborator

Problem:

Manual cleanup code is used for resources that can be automatically managed.

Solution:

Use of Try-With-Resources to enhance the overall stability, performance, and clarity of code, ensuring better resource management and minimizing potential issues related to improper resource handling.

@github-actions
Copy link

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@tobiasKaminsky
Copy link
Member

Pending manual tests

  • upload
  • upload via copy from another app to NC files ("upload content from apps").

Copy link
Collaborator

@alperozturk96 alperozturk96 left a comment

Choose a reason for hiding this comment

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

Hello

Thank you for the PR.

I'm currently experiencing an issue when attempting to upload files from other apps to the Nextcloud Files app.

Steps to Reproduce:

  1. Navigate to a folder in the app.
  2. Tap the "+" button at the bottom right.
  3. Select "Upload content from other apps".
E  Could not find source file content://com.android.externalstorage.documents/document/primary%3ADownload%2Ftea%2F0003.webp
   java.io.FileNotFoundException: /storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/tmp/[email protected]%3A55001/b4/0003.webp: open failed: ENOENT (No such file or directory)
   ...
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)

@alexknop
Copy link
Collaborator Author

Hello

Thank you for the PR.

I'm currently experiencing an issue when attempting to upload files from other apps to the Nextcloud Files app.

Steps to Reproduce:

1. Navigate to a folder in the app.

2. Tap the "+" button at the bottom right.

3. Select "Upload content from other apps".
E  Could not find source file content://com.android.externalstorage.documents/document/primary%3ADownload%2Ftea%2F0003.webp
   java.io.FileNotFoundException: /storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/tmp/[email protected]%3A55001/b4/0003.webp: open failed: ENOENT (No such file or directory)
   ...
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)

I am trying this myself and cannot reproduce it. It looks like you were attempting a .webp file from your Documents folder? Do you have a full trace of this error? I'd like to see where it could be breaking, but I'm assuming it's something in the normalUpload function....

@alexknop alexknop force-pushed the tryResources branch 2 times, most recently from fd030c4 to d9f273a Compare May 28, 2025 22:24
@alperozturk96
Copy link
Collaborator

Hello
Thank you for the PR.
I'm currently experiencing an issue when attempting to upload files from other apps to the Nextcloud Files app.
Steps to Reproduce:

1. Navigate to a folder in the app.

2. Tap the "+" button at the bottom right.

3. Select "Upload content from other apps".
E  Could not find source file content://com.android.externalstorage.documents/document/primary%3ADownload%2Ftea%2F0003.webp
   java.io.FileNotFoundException: /storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/tmp/[email protected]%3A55001/b4/0003.webp: open failed: ENOENT (No such file or directory)
   ...
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)

I am trying this myself and cannot reproduce it. It looks like you were attempting a .webp file from your Documents folder? Do you have a full trace of this error? I'd like to see where it could be breaking, but I'm assuming it's something in the normalUpload function....

E  Could not find source file content://com.android.externalstorage.documents/document/primary%3ADownload%2Fend%2F0028.webp  
   java.io.FileNotFoundException: 
   /storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/tmp/[email protected]/abc/0028.webp: 
   open failed: ENOENT (No such file or directory)

    at libcore.io.IoBridge.open(IoBridge.java:574)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:259)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:147)
    at com.owncloud.android.ui.asynctasks.CopyAndUploadContentUrisTask.doInBackground(CopyAndUploadContentUrisTask.java:149)
    at com.owncloud.android.ui.asynctasks.CopyAndUploadContentUrisTask.doInBackground(CopyAndUploadContentUrisTask.java:41)
    at android.os.AsyncTask$3.call(AsyncTask.java:394)
    at java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651)
    at java.lang.Thread.run(Thread.java:1119)

Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)

    at libcore.io.Linux.open(Native Method)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:568)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:568)
    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8953)
    at libcore.io.IoBridge.open(IoBridge.java:560)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:259)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:147)
    at com.owncloud.android.ui.asynctasks.CopyAndUploadContentUrisTask.doInBackground(CopyAndUploadContentUrisTask.java:149)
    at com.owncloud.android.ui.asynctasks.CopyAndUploadContentUrisTask.doInBackground(CopyAndUploadContentUrisTask.java:41)
    at android.os.AsyncTask$3.call(AsyncTask.java:394)
    at java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651)
    at java.lang.Thread.run(Thread.java:1119)

Here is the demo. Thank you.

dm.mp4

Signed-off-by: Alex Knop <[email protected]>
@alexknop
Copy link
Collaborator Author

@alperozturk96 I believe I fixed it. I had accidentally moved some commands into the try loop which were originally called before creating the FileOutputStream. This should now be synonymous with how the code was before.

@github-actions
Copy link

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/14583.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@github-actions
Copy link

Codacy

Lint

TypemasterPR
Warnings5151
Errors1111

SpotBugs

CategoryBaseNew
Bad practice6565
Correctness5860
Dodgy code292282
Experimental11
Internationalization77
Malicious code vulnerability11
Multithreaded correctness77
Performance5149
Security1818
Total500490

Copy link
Collaborator

@alperozturk96 alperozturk96 left a comment

Choose a reason for hiding this comment

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

Tested, works as expected.

@AndyScherzinger AndyScherzinger merged commit fa83d67 into master Jun 12, 2025
20 of 21 checks passed
@AndyScherzinger AndyScherzinger deleted the tryResources branch June 12, 2025 09:02
@AndyScherzinger AndyScherzinger added this to the Nextcloud App 3.32.0 milestone Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants