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

onActivityResult crashing when intent is null because promise is null #426

Closed
Shervanator opened this issue Dec 19, 2019 · 5 comments · Fixed by #427
Closed

onActivityResult crashing when intent is null because promise is null #426

Shervanator opened this issue Dec 19, 2019 · 5 comments · Fixed by #427

Comments

@Shervanator
Copy link
Contributor

Issue

This is related to the fix here: #352 and the initial issue here: #130

When onActivityResult is called (e.g. when returning to app from another app) the intent can be null. This triggers the following flow:

if (data == null) {
promise.reject("Failed to authenticate", "Data intent is null" );
return;
}

Which try's to do the following:

promise.reject("Failed to authenticate", "Data intent is null" );

However if none of the other exported functions in this module are called then the promise instance variable is null. Because the promise is only set when the other functions are called. e.g.

I think we should check if the promise is set before calling it in the onActivityResult function?

cc @AlgirdasVZ @kadikraman

I'm going to play around with a fix since this is effecting us in a production app at the moment!


Environment

  • Your Identity Provider: *
  • Platform that you're experiencing the issue on: Android
  • Are you using Expo?: no
  • Package version?: 5.0.0-rc3
@Shervanator
Copy link
Contributor Author

I've put together a PR that fixes the issue here: #427 would love to get this merged so we don't have to maintain a forked package! :D

@AlgirdasVZ
Copy link
Contributor

Hi, can you post here the full crash report of this issue?

@Shervanator
Copy link
Contributor Author

Shervanator commented Dec 19, 2019

hello! this is the crash:

12-19 08:51:45.417  4671  4671 E AndroidRuntime: FATAL EXCEPTION: main
12-19 08:51:45.417  4671  4671 E AndroidRuntime: Process: com.envato.MY_APP, PID: 4671
12-19 08:51:45.417  4671  4671 E AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=0, data=null} to activity {com.envato.development.MY_APP/MY_APP.MainActivity}: 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 reference
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4609)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4651)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1947)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:214)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7037)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 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 reference
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at com.rnappauth.RNAppAuthModule.onActivityResult(RNAppAuthModule.java:303)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:262)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.onActivityResult(ReactInstanceManager.java:703)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:124)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:75)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at MY_APP.MainActivity.onActivityResult(MainActivity.java:13)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.Activity.dispatchActivityResult(Activity.java:7759)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4602)
12-19 08:51:45.417  4671  4671 E AndroidRuntime: 	... 11 more

@AlgirdasVZ
Copy link
Contributor

AlgirdasVZ commented Dec 19, 2019

Hmm, interesting. How often do you see this crash? Maybe you have steps to reproduce this?

We are also using this in production for one app and so far we haven't had any crashes related to this after the fix. However, I was able to find a single occurrence of similar crash as yours (the crash caused by promise being a reference to null, but the difference is that intent is not null) in our other app crashlogs, which is still using the react-native-app-auth v4.4.0. Since the intent is not null in this case, the crash happens on a different line where promise.reject is also called.

Seems a bit strange though, since the onActivityResult is called when browser activity finishes and that browser activity can only be invoked by calling "authorize" method where the reference to promise is also set.

@Shervanator
Copy link
Contributor Author

So its very possible we have setup react-native-app-auth a little wrong, but basically this is what we have:

  • A react native app that uses react-native-app-auth to auth with a internal oauth provider
  • This android app has set the appAuthRedirectScheme to equal the applicationId (in this example: com.envato.MY_APP)
  • Auth works fine when returning from the browser to the device!
  • The app also has a flow where a user is able to share content to the instagram app installed on the users device. It does this via a android intent.
  • If the user hits the hardware back button on android it goes back to the com.envato.MY_APP app using a intent. This intent ends up bubbling up to call RNAppAuthModule.onActivityResult in this library. The intent is set to null.
  • The app will crash if the auth flow (RNAppAuthModule.authorize(...)) isn't called in the same app session (e.g. if you close the app after auth, then do this share to instagram flow)

I can constantly reproduce it :) Its very possible we are using react-native-app-auth wrong!

Thanks for you help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants