Skip to content

[Android] Don't start a null intent from WebAuthenticatorIntermediateActivity - #39194

Closed
MykhailoDav wants to merge 2 commits into
dotnet:mainfrom
MykhailoDav:fix-32000-android-webauthenticator-null-intent
Closed

MykhailoDav wants to merge 2 commits into
dotnet:mainfrom
MykhailoDav:fix-32000-android-webauthenticator-null-intent

Conversation

@MykhailoDav

Copy link
Copy Markdown
Contributor

Description of Change

On Android, WebAuthenticatorIntermediateActivity crashes the app when it's created without extras:

Java.Lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)' on a null object reference
   at Android.Content.ContextWrapper.StartActivity(Intent intent)
   at Microsoft.Maui.Authentication.WebAuthenticatorIntermediateActivity.OnResume()

The issue has crash reports from 9.0.110 and .NET 10. #24692 and #30414 reported the same crash.

Root cause

OnCreate returns early when there are no extras (both savedInstanceState and Intent.Extras are null), so actualIntent stays null and launched stays false. OnResume then calls StartActivity(actualIntent) with null.

Fix

In OnResume, if actualIntent is null on the first launch, the activity finishes instead of calling StartActivity. The check is where the crash happens, so it covers both ways actualIntent can be null: no extras at all, and extras without the intent.

Other paths are unchanged. An activity started by WebAuthenticatorIntermediateActivity.StartActivity always has the intent. When WebAuthenticatorCallbackActivity starts the activity again, it passes LaunchedExtra, so the callback branch still runs.

net11.0 rewrote this activity, and the rewrite finishes when there are no extras. So this change is only needed on main.

IntermediateActivity, which the pickers use, has the same pattern in OnCreate (StartActivityForResult(actualIntent, …)), but no crash has been reported for it, so it isn't changed here.

Tests

WebAuthenticatorIntermediateActivity_Tests.StartingWithoutExtrasFinishesTheActivity (Essentials.DeviceTests, Android) starts the activity without extras and waits for it to be destroyed. Android calls OnResume, so an exception thrown there would crash the test app. The test catches it with AndroidEnvironment.UnhandledExceptionRaiser instead, so it fails with an assertion.

Without fix With fix
StartingWithoutExtrasFinishesTheActivity Fails: NullPointerException from StartActivity in WebAuthenticatorIntermediateActivity.OnResume, and the activity stays open Passes; the activity finishes right away

With the fix, all 283 Essentials.DeviceTests pass on an API 37 emulator.

Issues Fixed

Fixes #32000

MykhailoDav and others added 2 commits October 6, 2026 21:17
…xtras

Without the fix, OnResume calls StartActivity(null), which throws a
NullPointerException (dotnet#32000).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Activity

When the activity is created without extras, OnCreate returns before it
reads the authentication intent, and OnResume then called
StartActivity(null), which crashed the app with a NullPointerException.
Finish the activity instead, since there's nothing to start.

Fixes dotnet#32000

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39194

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39194"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Oct 6, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

kubaflo

This comment was marked as low quality.

@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

/azp run

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 6, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15586333 is running for android.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@MykhailoDav

MykhailoDav commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you, @kubaflo , for your kind words!
I checked this on net11.0 (0b038e7). There, the rewritten WebAuthenticatorIntermediateActivity already finishes in OnCreate when there are no extras, so StartActivity(null) can't happen. This PR's test passes on net11.0 without the fix, so .NET 11 doesn't need this change. Closing.

My other open PRs, #39181, #39183 and #39193, still apply to net11.0. I rebased them onto it and retargeted them. Their tests fail on net11.0 without the fix and pass with it.

@MauiBot

MauiBot commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

AI Review Summary

@MykhailoDav — new AI review results are available based on commit 4e8411a.

Gate Passed Confidence Unknown Platform Android


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ✅ PASSED

Platform: ANDROID · Base: main · Merge base: 8c974ad7

Test Without Fix (expect FAIL) With Fix (expect PASS)
📱 WebAuthenticatorIntermediateActivity_Tests (StartingWithoutExtrasFinishesTheActivity) Category=WebAuthenticator ✅ FAIL — 480s ✅ PASS — 363s
🔴 Without fix — 📱 WebAuthenticatorIntermediateActivity_Tests (StartingWithoutExtrasFinishesTheActivity): FAIL ✅ · 480s

(no coded error found; showing last 1200 chars)

Bytes": 8322998272
          },
          "target": {
            "kind": "emulator",
            "name": "sdk_gphone_x86_64",
            "identifier": "emulator-5554",
            "operatingSystem": "Android",
            "operatingSystemVersion": "11",
            "apiLevel": 30,
            "architecture": "x86_64",
            "supportedArchitectures": [
              "x86_64",
              "x86",
              "arm64-v8a",
              "armeabi-v7a",
              "armeabi"
            ],
            "manufacturer": "Google",
            "model": "sdk_gphone_x86_64",
            "productName": "sdk_gphone_x86_64",
            "buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
            "cpuModel": "0",
            "cpuMaxFrequencyHertz": 2000,
            "totalMemoryBytes": 2077544448
          }
        }
      }
      <<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.essentials.devicetests'..
info: Successfully uninstalled com.microsoft.maui.essentials.devicetests
XHarness exit code: 1 (TESTS_FAILED)
  Passed: 0
  Failed: 1
  Skipped: 0
  Total: 1
  Tests completed with exit code: 1
🟢 With fix — 📱 WebAuthenticatorIntermediateActivity_Tests (StartingWithoutExtrasFinishesTheActivity): PASS ✅ · 363s

(no coded error found; showing last 1200 chars)

        "totalMemoryBytes": 8322998272
          },
          "target": {
            "kind": "emulator",
            "name": "sdk_gphone_x86_64",
            "identifier": "emulator-5554",
            "operatingSystem": "Android",
            "operatingSystemVersion": "11",
            "apiLevel": 30,
            "architecture": "x86_64",
            "supportedArchitectures": [
              "x86_64",
              "x86",
              "arm64-v8a",
              "armeabi-v7a",
              "armeabi"
            ],
            "manufacturer": "Google",
            "model": "sdk_gphone_x86_64",
            "productName": "sdk_gphone_x86_64",
            "buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
            "cpuModel": "0",
            "cpuMaxFrequencyHertz": 2000,
            "totalMemoryBytes": 2077544448
          }
        }
      }
      <<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.essentials.devicetests'..
info: Successfully uninstalled com.microsoft.maui.essentials.devicetests
XHarness exit code: 0
  Passed: 1
  Failed: 0
  Skipped: 0
  Total: 1
  Tests completed successfully
📁 Fix files reverted (1 files)
  • src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs

📋 Pre-Flight — Context & Validation

⚠️ Pre-Flight did not produce output on this run.

The Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase.

Next step: re-comment /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🔬 Code Review — Deep Analysis

⚠️ Code Review did not produce output on this run.

The Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase.

Next step: re-comment /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🛠️ Try-Fix — Analysis & Comparison

⚠️ Try-Fix did not produce output on this run.

The Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase.

Next step: re-comment /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🏁 Report — Final Recommendation

⚠️ Report / Final Recommendation did not produce output on this run.

The Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase.

Next step: re-comment /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


📱 UI Tests — Button,Label,Layout

Detected UI test categories: Button,Label,Layout

⚠️ Deep UI tests — 149 passed, 3 skipped; 1 category (79 tests) could not run: OneTimeSetUp/fixture setup failure on the platform-pool agent — infrastructure, not a PR test failure (replaces in-process counts above). The deep UI run for 1 category (Layout) exceeded the per-category time budget (a very long-running category or a slow build/deploy) and was stopped before finishing. This is an infrastructure/timeout issue, not a code problem; re-run the review, and if a category consistently needs more time the per-category budget can be raised (DEEP_UITEST_CATEGORY_CAP_MIN / DEEP_UITEST_HARDSTOP_MIN). See the build-output.log in the drop-deep-uitests artifact.

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
Button 104/106 (2 skipped) ✓ —
Label 45/125 (setup failed; 79 marked failed, 1 skipped) —
⚠️ Label — fixture setup failed for 79 tests

NUnit reported a OneTimeSetUp/fixture setup failure before test bodies ran; the TRX marked each affected test failed.

OneTimeSetUp: System.ObjectDisposedException : Cannot access a disposed object.
Object name: 'Accessing IApp that has been disposed'.
at UITest.Appium.AppiumUIClientContext.get_App() in /_/src/TestUtils/src/UITest.Appium/AppiumUIClientContext.cs:line 17
   at UITest.Appium.NUnit.UITestContextBase.get_App() in /_/src/TestUtils/src/UITest.NUnit/UITestContextBase.cs:line 32
   at UITest.Appium.NUnit.UITestBase.SaveUIDiagnosticInfo(String note, Boolean storeForReattachment) in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 288
   at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 228
   at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
   at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)


🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot added s/agent-review-incomplete AI review did not complete all expected phases s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 7, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 4e8411a4 Deployed Oct 6, 2026 by MykhailoDav via conclusion #2252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community ✨ Community Contribution s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-review-incomplete AI review did not complete all expected phases s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebAuthenticatorIntermediateActivity.onResume Still Crashes When Passed a Null Value

3 participants