Skip to content

NullPointerException in createConnectionBuilder (Android) #450

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

Closed
anderskristiansen opened this issue Jan 16, 2020 · 7 comments
Closed

NullPointerException in createConnectionBuilder (Android) #450

anderskristiansen opened this issue Jan 16, 2020 · 7 comments

Comments

@anderskristiansen
Copy link

anderskristiansen commented Jan 16, 2020

We just release a new app based on React Native and react-native-app-auth and Azure AD as IDP.

react-native-app-auth: 5.0.0-rc3
react-native: 0.61.5
react: 16.9.0

We never saw this during testing with emulator and a Huawei P30(Android 9).
But now we have logged hundreds of these errors over the last couple of days, on a range of different phone models, and Android 8, 9 and 10. iOS seems fine.

Based on the exception, it seems like dangerouslyAllowInsecureHttpRequests. How could this be?
This seems related to this issue: #95

Caused by java.lang.NullPointerException
Attempt to invoke virtual method 'boolean java.lang.Boolean.equals(java.lang.Object)' on a null 

com.rnappauth.RNAppAuthModule.createConnectionBuilder (RNAppAuthModule.java:546)
com.rnappauth.RNAppAuthModule.onActivityResult (RNAppAuthModule.java:316)
com.facebook.react.bridge.ReactContext.onActivityResult (ReactContext.java:275)
com.facebook.react.ReactInstanceManager.onActivityResult (ReactInstanceManager.java:703)
com.facebook.react.ReactDelegate.onActivityResult (ReactDelegate.java:89)
com.facebook.react.ReactActivityDelegate.onActivityResult (ReactActivityDelegate.java:110)
com.facebook.react.ReactActivity.onActivityResult (ReactActivity.java:67)
android.app.Activity.dispatchActivityResult (Activity.java:7193)
android.app.ActivityThread.deliverResults (ActivityThread.java:4280)
android.app.ActivityThread.handleSendResult (ActivityThread.java:4327)
android.app.ActivityThread.-wrap22 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1624)
android.os.Handler.dispatchMessage (Handler.java:105)
android.os.Looper.loop (Looper.java:156)
android.app.ActivityThread.main (ActivityThread.java:6523)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:942)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:832)
@anderskristiansen
Copy link
Author

We're also experiencing a great amount of these exceptions:

Caused by java.lang.NullPointerException
Attempt to invoke interface method 'void com.facebook.react.bridge.Promise.reject(java.lang.String, java.lang.String)' on a null object 

com.rnappauth.RNAppAuthModule.onActivityResult (RNAppAuthModule.java:310)
com.facebook.react.bridge.ReactContext.onActivityResult (ReactContext.java:275)
com.facebook.react.ReactInstanceManager.onActivityResult (ReactInstanceManager.java:703)
com.facebook.react.ReactDelegate.onActivityResult (ReactDelegate.java:89)
com.facebook.react.ReactActivityDelegate.onActivityResult (ReactActivityDelegate.java:110)
com.facebook.react.ReactActivity.onActivityResult (ReactActivity.java:67)
android.app.Activity.dispatchActivityResult (Activity.java:7762)
android.app.ActivityThread.deliverResults (ActivityThread.java:4603)
android.app.ActivityThread.handleSendResult (ActivityThread.java:4652)
android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:49)
android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108)
android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1948)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:214)
android.app.ActivityThread.main (ActivityThread.java:7050)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)

It seems like the RNAppAuthModule state is lost when the result from login returns? In this case this.promise is null.

@kadikraman
Copy link
Contributor

Hi - could you try upgrading to v5? It includes this PR which should prevent the native crashes. As for the other error - could you explain how you're using authentication in your app? Are you using prefetchConfiguration? It's going to be quite hard to debug this without being able to reproduce it.

@anderskristiansen
Copy link
Author

Thanks. I will try to roll out with v.5.0.0 stable today.

I am using this config:

 const endpoint = `https://login.microsoftonline.com/${TENANT}/oauth2/v2.0`;
  return {
    serviceConfiguration: {
      authorizationEndpoint: `${endpoint}/authorize`,
      tokenEndpoint: `${endpoint}/token`,
      revocationEndpoint: `${endpoint}/logout`,
    },
    clientId: '${clientId}',
    redirectUrl: Platform.OS === 'ios' ? 'urn:ietf:wg:oauth:2.0:oob' : 'myapp://auth',
    scopes: ['openid', 'profile', 'email', 'offline_access'],
    additionalParameters: {
      prompt: 'login',
    }
 }

Using authorize to log in (no prefetch):

export const login = () => {
  return authorize(azureAdConfig()).then(token => {
    return store.dispatch(saveUserToken(token));
  });
};

@kadikraman
Copy link
Contributor

Thanks for the clarification. Please let me know about if upgrading to v5 changes anything.

I think the issue might occur when the app is backgrounded for a while, and not related to any particular IDP. That would explain why we don't see it on the emulator. I will try to recreate this with on a physical Android device.

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Jan 30, 2020

@kadikraman I am using v5 and see this crash on Crashlytics today.

Brand: HUAWEI
Model: 荣耀8X Max
Orientation: Portrait
RAM free: 933.23 MB
Disk free: 2.1 GB

Version: 8.1.0
Orientation: Portrait
Rooted: No

@DrSchrumpfi
Copy link

@kadikraman We are using 5.0.2 and getting a lot of reports via Google Play Console:

Caused by: java.lang.NullPointerException:
at com.rnappauth.RNAppAuthModule.createConnectionBuilder (RNAppAuthModule.java:713)
at com.rnappauth.RNAppAuthModule.onActivityResult (RNAppAuthModule.java:396)
at com.facebook.react.bridge.ReactContext.onActivityResult (ReactContext.java:275)
at com.facebook.react.ReactInstanceManager.onActivityResult (ReactInstanceManager.java:703)
at com.facebook.react.ReactDelegate.onActivityResult (ReactDelegate.java:89)
at com.facebook.react.ReactActivityDelegate.onActivityResult (ReactActivityDelegate.java:110)
at com.facebook.react.ReactActivity.onActivityResult (ReactActivity.java:67)
at android.app.Activity.dispatchActivityResult (Activity.java:7393)
at android.app.ActivityThread.deliverResults (ActivityThread.java:4560)

Changing line 713 to

if (Boolean.TRUE.equals(allowInsecureConnections)) {

might help.

@thymikee
Copy link

Looks like this is fixed by 0b356a5, included in v5.1.2. Please close this issue :)

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

No branches or pull requests

5 participants