flutter_appauth icon indicating copy to clipboard operation
flutter_appauth copied to clipboard

FlutterAppauthPlugin.java line, io.crossingthestreams.flutterappauth.FlutterAppauthPlugin.a

Open bhanuka96 opened this issue 4 years ago • 6 comments

Is there any way to fix this issue?

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void net.openid.appauth.g.a(net.openid.appauth.r, net.openid.appauth.g$b)' on a null object reference
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin.a(FlutterAppauthPlugin.java:82)
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin.access$300(FlutterAppauthPlugin.java)
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin$4.onFetchConfigurationCompleted(FlutterAppauthPlugin.java:6)
       at net.openid.appauth.AuthorizationServiceConfiguration$ConfigurationRetrievalAsyncTask.a(AuthorizationServiceConfiguration.java:13)
       at net.openid.appauth.AuthorizationServiceConfiguration$ConfigurationRetrievalAsyncTask.onPostExecute(AuthorizationServiceConfiguration.java:2)
       at android.os.AsyncTask.finish(AsyncTask.java:755)
       at android.os.AsyncTask.access$900(AsyncTask.java:192)
       at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7562)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Button Click code

  @override
  Future<AuthorizationTokenResponse?> login(TenantCatLogModel? tenantCatLogModel) async {
    FlutterAppAuth appAuth = FlutterAppAuth();
    final String _issuer = '${tenantCatLogModel?.authorityUrl}';
    final AuthorizationServiceConfiguration _serviceConfiguration = AuthorizationServiceConfiguration(
        '${tenantCatLogModel?.authorityUrl}/connect/authorize', '${tenantCatLogModel?.authorityUrl}/connect/token');

    return appAuth
        .authorizeAndExchangeCode(AuthorizationTokenRequest(
      _clientId, _redirectUrl,
      issuer: _issuer,
      scopes: _scopes,
      promptValues: ['login'],
      serviceConfiguration: _serviceConfiguration,
      preferEphemeralSession: Platform.isIOS
    )).catchError((e) async {
      return null;
    }).then((value) async {
      log('access token -> ${value?.accessToken}');
      if (value?.refreshToken != null) {
        await SecureStore().setRToken(value?.refreshToken);
        return value;
      } else {
        return null;
      }
    });
  }

bhanuka96 avatar Sep 07 '21 04:09 bhanuka96

Not something I can look into without a minimal app that can reproduce the issue so it would need to be something you'd have to debug to find out

MaikuB avatar Sep 08 '21 08:09 MaikuB

We are seeing a very similar error in our crashlytics:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void net.openid.appauth.g.a(net.openid.appauth.r, net.openid.appauth.g$b)' on a null object reference
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin.a(FlutterAppauthPlugin.java:82)
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin.access$300(FlutterAppauthPlugin.java)
       at io.crossingthestreams.flutterappauth.FlutterAppauthPlugin$4.onFetchConfigurationCompleted(FlutterAppauthPlugin.java:6)
       at net.openid.appauth.AuthorizationServiceConfiguration$ConfigurationRetrievalAsyncTask.a(AuthorizationServiceConfiguration.java:13)
       at net.openid.appauth.AuthorizationServiceConfiguration$ConfigurationRetrievalAsyncTask.onPostExecute(AuthorizationServiceConfiguration.java:2)
       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:264)
       at android.app.ActivityThread.main(ActivityThread.java:8245)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)

image

From what I can deduce, it's an issue related to configuration fetching. Have not been able to reproduce it.

Xylez01 avatar Sep 27 '21 06:09 Xylez01

Based on the stacktrace, it's executing this block:

https://github.com/MaikuB/flutter_appauth/blob/92cc21bb7e07684adc1c5265f63d1429982b9451/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java#L352-L354

But the authorizationService seems to be null?

Could it be that the config callback gets triggered, but everything is somehow already disposed?

Xylez01 avatar Sep 27 '21 06:09 Xylez01

@JordyLangen that I've seen based on what's been provided but it doesn't help much given there's a line to assign that authorizationService. To properly diagnose this issue would require steps to reproduce

MaikuB avatar Sep 28 '21 09:09 MaikuB

@MaikuB could it be that either insecureAuthorizationService or defaultAuthorizationService is null? So then authorizationService is assigned to be null...

Would be good to have this crash fixed!

PieterAelse avatar Dec 22 '21 09:12 PieterAelse

@PieterAelse Except no one has provided info on how it could be null. The code is open-source so you should be able to see both of those are being set when the Flutter engine is being attached. It's only set to null when the plugin is meant to clean up resources. If you're experiencing the issue then since it is open-source, you can debug further, try to fix it and submit a PR back to the repository

MaikuB avatar Jan 05 '22 10:01 MaikuB