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

[pay_android] GooglePayHandler.onActivityResult kotlin.UninitializedPropertyAccessException - lateinit property loadPaymentDataResult has not been initialized #261

Open
ekaterina-demeshko-idf opened this issue Apr 30, 2024 · 7 comments

Comments

@ekaterina-demeshko-idf
Copy link

We are getting crashes on new 2.0.0 version of pay

This issue has 4 crash events affecting 4 users in the last 48 hours.
Users are Samsung or xiomi, Android 13 and 14.
The stacktrace:

Caused by kotlin.UninitializedPropertyAccessException: lateinit property loadPaymentDataResult has not been initialized
       at io.flutter.plugins.pay_android.GooglePayHandler.onActivityResult(GooglePayHandler.kt:186)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEngineConnectionRegistry.java:774)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult(FlutterEngineConnectionRegistry.java:422)
       at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:857)
       at io.flutter.embedding.android.FlutterFragment.onActivityResult(FlutterFragment.java:1251)
       at io.flutter.embedding.android.FlutterFragmentActivity.onActivityResult(FlutterFragmentActivity.java:653)
       at android.app.Activity.dispatchActivityResult(Activity.java:8951)
       at android.app.ActivityThread.deliverResults(ActivityThread.java:5987)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5348)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5444)
       at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8762)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
       
       Caused by java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=991, result=0, data=null} to activity {es.card.plazo/es.card.plazo.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property loadPaymentDataResult has not been initialized
       at android.app.ActivityThread.deliverResults(ActivityThread.java:5994)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5348)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5444)
       at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8762)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
       ```

If you need more details, please request . 
@JlUgia
Copy link
Member

JlUgia commented May 9, 2024

Hello @ekaterina-demeshko-idf.
GooglePayHandler:186 is part of the onActivityResult callback, and is executed when an activity result with request code: LOAD_PAYMENT_DATA_REQUEST_CODE and result code: Activity.RESULT_CANCELED is received. In the context of the plugin, this only happens when a call to loadPaymentData is issued at GooglePayHandler:151, which also sets the loadPaymentDataResult lateinit variable, hence this is unexpected.

Are you able to determine steps to reproduce this?
Are you issuing other activity for results requests? If you do, can you verify that you are not using 991 as a request code in these calls like this plugin does?

@ekaterina-demeshko-idf
Copy link
Author

Hello @JlUgia we are using showPaymentSelector and userCanPay methods of Pay class.
Currently it was not possible to reproduce the crash and determine exact steps.
Although we are not issuing any other activities for pay.

@ekaterina-demeshko-idf
Copy link
Author

Hello @JlUgia

We have encountered additional crashes related to the GooglePayHandler in the new 2.0.0 version of the pay plugin. Here are the details of the new stack trace:


Failure delivering result ResultInfo{who=null, request=991, result=-1, data=Intent { (has extras) }} to activity {MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property loadPaymentDataResult has not been initialized
UninitializedPropertyAccessException
lateinit property loadPaymentDataResult has not been initialized

io.flutter.plugins.pay_android.GooglePayHandler in handlePaymentSuccess at line 216
io.flutter.plugins.pay_android.GooglePayHandler in onActivityResult at line 180

The issue seems to occur when handlePaymentSuccess is called and the paymentData is not null, but loadPaymentDataResult has not been initialized in time. It appears that an additional instance of GooglePayHandler is created, leading to a scenario where the result is received by an instance where loadPaymentData was not called. It turns out that in one instance, the loadPaymentData function was called, where loadPaymentDataResult was initialized, the resolve task function was called from it, and the result already arrived in another instance of GooglePayHandler, where loadPaymentData was not called. However, since the callback exists, the request code and intent result were received. Seems like this causes the UninitializedPropertyAccessException for loadPaymentDataResult.

Do you have any suggestions on how we can address this issue or any additional checks we should implement to prevent this?

Thank you for your assistance.

@viktor-savchik-idf
Copy link

viktor-savchik-idf commented Jun 3, 2024

Hello guys, any updates here?

@ViniciusDeep
Copy link

Crash on Payment Success Handling in GooglePay Plugin

Hello,

We've encountered a crash that is significantly impacting some of our clients using the GooglePay plugin in Flutter. The crash occurs when handling payment success, affecting over 350 users.

Here is the relevant stack trace:

io.flutter.plugins.pay_android.GooglePayHandler.handlePaymentSuccess (GooglePayHandler.java:6)
io.flutter.plugins.pay_android.GooglePayHandler.onActivityResult (GooglePayHandler.java:6)
io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult (FlutterEngineConnectionRegistry.java:25)
io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult (FlutterEngineConnectionRegistry.java:13)
io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.m (FlutterActivityAndFragmentDelegate.java:16)
io.flutter.embedding.android.FlutterFragment.onActivityResult (FlutterFragment.java:10)
io.flutter.embedding.android.FlutterFragmentActivity.onActivityResult (FlutterFragmentActivity.java:5)

This issue is causing crashes on the payment success handler, and it is currently affecting a significant number of our users.

Impact:

  • Number of affected users: 350+

It is basically the same thing that was described above, do you happen to have any updates here?

@ViniciusDeep
Copy link

This PR should fix: #276 (review)

I think that we can wait until the release for now

@aggeloskoutanis
Copy link

Are there any updates on when this is going to be fixed? We are also having the exact same 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