Skip to content

Conversation

@SamCosta1
Copy link
Contributor

Context

We've seen a couple of instances in our crashlytics logs of a crash happening due to the activity object being null when startActivityForResult is called.

Crash log

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.startActivityForResult(android.content.Intent, int)' on a null object reference
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin.performAuthorization(FlutterAppauthPlugin.java:465)
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin.access$300(FlutterAppauthPlugin.java)
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin$1.onFetchConfigurationCompleted(FlutterAppauthPlugin.java:331)
       at net.openid.appauth.AuthorizationServiceConfiguration$ConfigurationRetrievalAsyncTask.onPostExecute(AuthorizationServiceConfiguration.java:417)
       at net.openid.appauth.AuthorizationServiceConfiguration$ConfigurationRetrievalAsyncTask.onPostExecute(AuthorizationServiceConfiguration.java:358)
       at android.os.AsyncTask.finish(AsyncTask.java:771)
       at android.os.AsyncTask.access$900(AsyncTask.java:199)
       at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:233)
       at android.app.ActivityThread.main(ActivityThread.java:8063)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

Solution

A null check with a new error code

Alternative solutions considered

Possibly a more robust solution would be an exponential backoff waiting for the activity to be re-attached with a timeout. Given the maturity of this library though it seems (from what I can see) this issue is very rare, and adding more complexity seems unneeded. Handling it elegently seems sufficient to me.

Copy link
Owner

@MaikuB MaikuB left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I left a comment about renaming a variable as ERROR was being repeated. Could you take a look?

@MaikuB MaikuB merged commit 34dcd59 into MaikuB:master Oct 26, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants