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

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetFileDescriptor android.content.ContentResolver.openAssetFileDescriptor(android.net.Uri, java.lang.String)' on a null object reference #171

Closed
ManuelRosa opened this issue Dec 2, 2020 · 9 comments
Labels
wontfix This will not be worked on

Comments

@ManuelRosa
Copy link

I am getting the following exception:

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:354)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
       at java.util.concurrent.FutureTask.run(FutureTask.java:271)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:764)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetFileDescriptor android.content.ContentResolver.openAssetFileDescriptor(android.net.Uri, java.lang.String)' on a null object reference
       at android.provider.ContactsContract$Contacts.openContactPhotoInputStream(ContactsContract.java:2142)
       at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.loadContactPhotoHighRes(ContactsServicePlugin.java:647)
       at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.access$700(ContactsServicePlugin.java:54)
       at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:434)
       at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:405)
       at android.os.AsyncTask$2.call(AsyncTask.java:333)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:764)

Following the stack tree it seems that the problem occurs in the frameworks/base/core/java/android/provider/ContactsContract.java when the content resolver is null

                try {
                    AssetFileDescriptor fd = cr.openAssetFileDescriptor(displayPhotoUri, "r");
                    if (fd != null) {
                        return fd.createInputStream();
                    }
                } catch (IOException e) {
                    // fallback to the thumbnail code
                }

Looking at the plug-in code there is one place on the onDetachedFromEngine method where this is set to null:

  @Override
  public void onDetachedFromEngine(FlutterPluginBinding binding) {
    methodChannel.setMethodCallHandler(null);
    methodChannel = null;
    contentResolver = null;
    this.delegate = null;
  }

I am getting crash reports for this problem but I cannot simply reproduced them in my app. My best guess is that it might be related with the running the getContacts call in the background and then closing the app.

Is this a known issue? Anyone else having the same problem?

Thanks for the support

@AkankshaKS
Copy link

Hi @ManuelRosa , were you able to solve this, I am also getting various crashes giving the same logs.

@ManuelRosa
Copy link
Author

Hi @AkankshaKS . No, sadly I was not able to fix this problem yet and I am still getting this logs. Not sure if/when I will have the time to look at this personally.

@em-azhar
Copy link

Same problem here😭

@rubinbasha
Copy link

I am also running into the same issue on production. Is there any development on the matter?
Would at least a Null check help in this case and that would just fallback to "// fallback to the thumbnail code" just like the Catch clause does?

@rubinbasha
Copy link

Also just for learning reasons wanted to ask, is it possible to migrate to Kotlin as generally its safer? I speak as an Android Developer and my life has been changed to the better once I used Kotlin on my projects 😄

@rubinbasha
Copy link

any news on this issue, it is actually starting to affect multiple users in production for my app

@stale
Copy link

stale bot commented May 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label May 28, 2021
@stale stale bot closed this as completed Jun 4, 2021
@TimYusR
Copy link

TimYusR commented Oct 25, 2022

Having the same issue, version 0.6.3

Can't reproduce either

Screenshot 2022-10-25 at 23 37 15

@DVendy
Copy link

DVendy commented Nov 29, 2022

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

6 participants