dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

WebAuthenticator crashes on first start of browser #24692

Open DonkeyKongJr opened 3 weeks ago

DonkeyKongJr commented 3 weeks ago

Description

The error appears occasionally in our AppCenter Diagnostics logs, but now it seems we have figured out the root cause. The WebAuthenticatorIntermediateActivity crashes with NullPointerException even when using Chrome as the default browser and for the login process. However, this only crashes on the first start of Chrome where the browser wants you to login with your google account. Typically we continue without the google sign-in and our login page appears. After we entered the credentials, this error appears. If we try to login again (from our app), Google opens up without that question and the login eventually succeeds.

WebAuthenticatorIntermediateActivity.onResume
WebAuthenticatorIntermediateActivity.java, line 41
Java.Lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)' on a null object reference

Steps to Reproduce

Link to public reproduction project repository

No response

Version with bug

8.0.80 SR8

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11 and up

Did you find any workaround?

Well, if the user starts the login again, everything seems to be working fine.

Relevant log output

crc6468b6408a11370c2f.WebAuthenticatorIntermediateActivity.onResume
WebAuthenticatorIntermediateActivity.java, line 41
Java.Lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)' on a null object reference

Stack Trace:
Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference , JniObjectReference , JniMethodInfo , JniArgumentValue* )
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String , IJavaPeerable , JniArgumentValue* )
Android.Content.ContextWrapper.StartActivity(Intent )
Microsoft.Maui.Authentication.WebAuthenticatorIntermediateActivity.OnResume()
Android.App.Activity.n_OnResume(IntPtr jnienv, IntPtr native__this)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)' on a null object reference
android.app.Instrumentation.execStartActivity Instrumentation.java:1871
android.app.Activity.startActivityForResult Activity.java:5838
android.app.Activity.startActivityForResult Activity.java:5796
android.app.Activity.startActivity Activity.java:6294
android.app.Activity.startActivity Activity.java:6261
crc6468b6408a11370c2f.WebAuthenticatorIntermediateActivity.n_onResume(Native Method)
crc6468b6408a11370c2f.WebAuthenticatorIntermediateActivity.onResume WebAuthenticatorIntermediateActivity.java:41
android.app.Instrumentation.callActivityOnResume Instrumentation.java:1603
android.app.Activity.performResume Activity.java:9084
android.app.ActivityThread.performResumeActivity ActivityThread.java:5534
android.app.ActivityThread.handleResumeActivity ActivityThread.java:5582
android.app.servertransaction.ResumeActivityItem.execute ResumeActivityItem.java:57
android.app.servertransaction.ActivityTransactionItem.execute ActivityTransactionItem.java:45
android.app.servertransaction.TransactionExecutor.executeLifecycleState TransactionExecutor.java:180
android.app.servertransaction.TransactionExecutor.execute TransactionExecutor.java:98
android.app.ActivityThread$H.handleMessage ActivityThread.java:2853
android.os.Handler.dispatchMessage Handler.java:108
android.os.Looper.loopOnce Looper.java:226
android.os.Looper.loop Looper.java:328
android.app.ActivityThread.main ActivityThread.java:9220
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:586
com.android.internal.os.ZygoteInit.main ZygoteInit.java:1099
github-actions[bot] commented 3 weeks ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

mattleibow commented 3 weeks ago

@jonathanpeppers does this look familiar? Seems strange that the method would be missing as we don't really do anything with Intent.

jonathanpeppers commented 3 weeks ago

@DonkeyKongJr can you find WebAuthenticatorIntermediateActivity.java in your obj directory? What is on line 41?

The stack trace also shows onResume / startActivity, and it doesn't look like we handle a null actualIntent:

https://github.com/dotnet/maui/blob/9a78453108d3144f9858860b4d196648ae849ede/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs#L46

I wonder if it's just throwing NullPointerException if you pass in null here.

DonkeyKongJr commented 3 weeks ago

Line 41 is calling the n_onResume () method.

30  public void onResume ()
40  {
41      n_onResume ();
42  }

Here is the whole content:

package crc6468b6408a11370c2f;

public class WebAuthenticatorIntermediateActivity
    extends android.app.Activity
    implements
        mono.android.IGCUserPeer
{
/** @hide */
    public static final String __md_methods;
    static {
        __md_methods = 
            "n_onCreate:(Landroid/os/Bundle;)V:GetOnCreate_Landroid_os_Bundle_Handler\n" +
            "n_onResume:()V:GetOnResumeHandler\n" +
            "n_onNewIntent:(Landroid/content/Intent;)V:GetOnNewIntent_Landroid_content_Intent_Handler\n" +
            "n_onSaveInstanceState:(Landroid/os/Bundle;)V:GetOnSaveInstanceState_Landroid_os_Bundle_Handler\n" +
            "";
        mono.android.Runtime.register ("Microsoft.Maui.Authentication.WebAuthenticatorIntermediateActivity, Microsoft.Maui.Essentials", WebAuthenticatorIntermediateActivity.class, __md_methods);
    }

    public WebAuthenticatorIntermediateActivity ()
    {
        super ();
        if (getClass () == WebAuthenticatorIntermediateActivity.class) {
            mono.android.TypeManager.Activate ("Microsoft.Maui.Authentication.WebAuthenticatorIntermediateActivity, Microsoft.Maui.Essentials", "", this, new java.lang.Object[] {  });
        }
    }

    public void onCreate (android.os.Bundle p0)
    {
        n_onCreate (p0);
    }

    private native void n_onCreate (android.os.Bundle p0);

    public void onResume ()
    {
        n_onResume ();
    }

    private native void n_onResume ();

    public void onNewIntent (android.content.Intent p0)
    {
        n_onNewIntent (p0);
    }

    private native void n_onNewIntent (android.content.Intent p0);

    public void onSaveInstanceState (android.os.Bundle p0)
    {
        n_onSaveInstanceState (p0);
    }

    private native void n_onSaveInstanceState (android.os.Bundle p0);

    private java.util.ArrayList refList;
    public void monodroidAddReference (java.lang.Object obj)
    {
        if (refList == null)
            refList = new java.util.ArrayList ();
        refList.add (obj);
    }

    public void monodroidClearReferences ()
    {
        if (refList != null)
            refList.clear ();
    }
}
mattleibow commented 2 weeks ago

Is it possible to attach a video of the steps you are taking so that we can try repro this?

You say:

However, this only crashes on the first start of Chrome where the browser wants you to login with your google account. Typically we continue without the google sign-in and our login page appears. After we entered the credentials, this error appears.

And then:

On the first start Google Chrome asks about your Google Account, proceed without the Google Account

Just trying to clarify the options you pick.

DonkeyKongJr commented 2 weeks ago

Sure @mattleibow,

I hope this helps. As soon as I click login and the redirect starts, the app crashes, but only if the Chrome dialog appears. After that first crash and a restart of the App, the login works.

This happens every time we create a new emulator.

https://github.com/user-attachments/assets/20c0e359-75c6-4607-bff7-cdf6baf1c57e