Skip to content

NullPointerException in ReactNativeBlobUtilFS.lstat #425

@nigelsim

Description

@nigelsim

I'm getting the following NPE when calling lstat on a folder in /Android/data. I believe that the underlying issue is that even though my app has permission to view all files, that there is still an underlying permissions issue.

But, the behaviour of an NPE still seems incorrect.

06-23 16:02:56.263 18019 18052 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to get length of null array
06-23 16:02:56.263 18019 18052 E AndroidRuntime:        at com.ReactNativeBlobUtil.ReactNativeBlobUtilFS$1.doInBackground(ReactNativeBlobUtilFS.java:746)
06-23 16:02:56.263 18019 18052 E AndroidRuntime:        at com.ReactNativeBlobUtil.ReactNativeBlobUtilFS$1.doInBackground(ReactNativeBlobUtilFS.java:729)
06-23 16:02:56.263 18019 18052 E AndroidRuntime:        at android.os.AsyncTask$3.call(AsyncTask.java:394)
06-23 16:02:56.263 18019 18052 E AndroidRuntime:        at java.util.concurrent.FutureTask.run(FutureTask.java:264)

Interestingly, it seems this situation isn't fixed by checking if the path is a directory, as the existing code already does this. I'm not sure if the answer is to just do a null check, or if there is another test that can be done on the folder first. Hopefully someone with more platform experience can assist with that decision.

                if (src.isDirectory()) {
                    String[] files = src.list();
                    // File => list(): "If this abstract pathname does not denote a directory, then this method returns null."
                    // We excluded that possibility above - ignore the "can produce NullPointerException" warning of the IDE.
                    for (String p : files) {

I'm using react-native-blob-util 0.18.6 due to this needing to run on old versions of Android therefore old versions of RN, but this code doesn't seem to have changed recently, and this particular error is occurring on Android 13.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions