Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Filesystem.writeFile throws java.lang.ArrayIndexOutOfBoundsException when base64Data passed is empty #7730

Closed
1 of 3 tasks
braincomb opened this issue Oct 23, 2024 · 3 comments
Labels
needs reproduction needs reproducible example to illustrate the issue

Comments

@braincomb
Copy link

braincomb commented Oct 23, 2024

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 6.1.2
@capacitor/core: 6.1.2
@capacitor/android: 6.1.2
@capacitor/ios: 6.1.2

Installed Dependencies:

@capacitor/cli: 6.1.2
@capacitor/core: 6.1.2
@capacitor/android: 6.1.2
@capacitor/ios: 6.1.2

[error] Xcode is not installed
[success] Android looking great! 👌

Other API Details

No response

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

Relevant web layer code:

      const imageName = "image.jpg";
      const fileContent = await fetch(`/assets/${imageName}`);
      const blob = await fileContent.blob();
      const base64Data = (await convertBlobToBase64(blob)) as string;

      // Write the file to cache directory
      const savedFile = await Filesystem.writeFile({
        path: imageName,
        data: base64Data,
        directory: Directory.Cache,
      });

When file is found and it forms a proper base64Data, the application works as expected. However, when I mistyped the fetch path to /public/assets/${imageName}, the file was not found and therefore base64Data formed was empty like so: data:image/jpeg;base64,, this causes Filesystem.writeFile to crash the application:

23:01:27.588 E Unable to open asset URL: http://localhost/public/assets/image.jpg
23:01:27.611 V To native (Capacitor plugin): callbackId: 109817524, pluginId: Filesystem, methodName: writeFile
23:01:27.611 V callback: 109817524, pluginId: Filesystem, methodName: writeFile, methodData: {"path":"image.jpg","data":"data:image/jpeg;base64,","directory":"CACHE"}
23:01:27.612 E Serious error executing plugin
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:821)

Full stacktrace attached:
stacktrace.txt

Expected Behavior

When base64Data passed is empty, I expect the application to not crash and simply return and propagate the error to the web layer.

Project Reproduction

N/A

Additional Information

No response

@braincomb braincomb changed the title [Bug]: Filesystem.writeFile throws java.lang.ArrayIndexOutOfBoundsException when file is not found [Bug]: Filesystem.writeFile throws java.lang.ArrayIndexOutOfBoundsException when base64Data passed is empty Oct 23, 2024
@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label Oct 23, 2024
Copy link

ionitron-bot bot commented Oct 23, 2024

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.
Please see the Contributing Guide for how to create a Sample App.
Thanks! Ionitron 💙

@ionitron-bot ionitron-bot bot removed the triage label Oct 23, 2024
@Ionitron Ionitron added needs reply needs reply from the user and removed needs reply needs reply from the user labels Oct 23, 2024
@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Oct 23, 2024
@Ionitron
Copy link
Collaborator

Ionitron commented Nov 8, 2024

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day!
Ionitron 💙

@Ionitron Ionitron closed this as completed Nov 8, 2024
@Ionitron Ionitron removed the needs reply needs reply from the user label Nov 8, 2024
Copy link

ionitron-bot bot commented Dec 8, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Dec 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction needs reproducible example to illustrate the issue
Projects
None yet
Development

No branches or pull requests

3 participants