Skip to content

Fix RecorderWindowCallback crash on null menu parameter#3239

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
developfrom
lan.nguyen/fix-recorder-window-callback-null-menu-crash-v2
Mar 10, 2026
Merged

Fix RecorderWindowCallback crash on null menu parameter#3239
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
developfrom
lan.nguyen/fix-recorder-window-callback-null-menu-crash-v2

Conversation

@nguyexua

@nguyexua nguyexua commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Overrides menu-related Window.Callback methods in RecorderWindowCallback with nullable parameters, preventing Kotlin's non-null assertions from crashing when Android passes null values.

Motivation

A customer reported a crash (NullPointerException: Parameter specified as non-null is null: method RecorderWindowCallback.onMenuOpened, parameter p1) when opening a custom popup menu.

RecorderWindowCallback uses Kotlin's by wrappedCallback delegation for Window.Callback. Kotlin generates non-null assertions for all delegated parameters, but Android can call these methods with null values (known Android bug: https://issuetracker.google.com/issues/188568911). The previous fix only handled dispatchTouchEvent with a try-catch, but the same issue affected all menu-related callbacks.

Changes

  • Override onMenuOpened, onMenuItemSelected, onPanelClosed, onPreparePanel, and onCreatePanelMenu in RecorderWindowCallback with nullable parameters. When null is received, methods return safe defaults (false or no-op) instead of crashing.
  • Remove the dispatchTouchEvent try-catch workaround and logOrRethrowWrappedCallbackException helper, since dispatchTouchEvent already declares its parameter as nullable.
  • Add tests for menu callback delegation and null-parameter handling.
  • Remove obsolete try-catch tests and unused imports.

Note

This is an alternative to #3221 with a simpler approach: nullable Kotlin overrides instead of a FixedWindowCallback Java wrapper class. No new files, no API surface change, no inheritance change.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@nguyexua
nguyexua force-pushed the lan.nguyen/fix-recorder-window-callback-null-menu-crash-v2 branch 2 times, most recently from a3dc505 to f460c15 Compare March 6, 2026 14:31
@datadog-datadog-prod-us1-2

This comment has been minimized.

@codecov-commenter

codecov-commenter commented Mar 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.38%. Comparing base (ba162fa) to head (442230c).
⚠️ Report is 18 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3239      +/-   ##
===========================================
- Coverage    71.49%   71.38%   -0.11%     
===========================================
  Files          934      934              
  Lines        34628    34628              
  Branches      5862     5862              
===========================================
- Hits         24755    24718      -37     
- Misses        8231     8264      +33     
- Partials      1642     1646       +4     
Files with missing lines Coverage Δ
...og/android/internal/utils/FixedWindowCallback.java 0.00% <ø> (ø)
.../instrumentation/gestures/WindowCallbackWrapper.kt 84.34% <ø> (ø)
...nternal/utils/window/RumWindowCallbacksRegistry.kt 92.31% <ø> (ø)
...ternal/recorder/callback/RecorderWindowCallback.kt 92.22% <100.00%> (ø)

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nguyexua
nguyexua marked this pull request as ready for review March 9, 2026 08:57
@nguyexua
nguyexua requested review from a team as code owners March 9, 2026 08:57

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 493ec41725

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

@Suppress("SwallowedException", "UnsafeThirdPartyFunctionCall") // NPE caught below
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Declare menu callback args nullable

These overrides still use non-null parameter types (Menu/MenuItem), so Kotlin emits checkNotNullParameter at method entry and throws before the try/catch can run when the framework passes null. In the null-menu scenario this patch is targeting, onMenuOpened (and the similarly typed onMenuItemSelected, onPanelClosed, onPreparePanel, onCreatePanelMenu) can still crash before delegating.

Useful? React with 👍 / 👎.

@nguyexua
nguyexua force-pushed the lan.nguyen/fix-recorder-window-callback-null-menu-crash-v2 branch 2 times, most recently from bda200b to c8dd0cb Compare March 9, 2026 09:18
*/
@RunWith(AndroidJUnit4::class)
@LargeTest
internal class AppStartupActivityPredicateTest :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the change in this file is related to this PR, if not, we need to revert it.

dependencies {
api(project(":dd-sdk-android-core"))
implementation(project(":dd-sdk-android-internal"))
compileOnly(project(":features:dd-sdk-android-rum"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

It's better just to move FixedWindowCallback into dd-sdk-android-internal module (suggested package: "com.datadog.android.internal.utils") instead of letting session replay depend on the whole rum module.

Extend FixedWindowCallback instead of using try-catch overrides, matching
the pattern established in PR #2800. Add compileOnly dependency on
dd-sdk-android-rum to access FixedWindowCallback.
@nguyexua
nguyexua force-pushed the lan.nguyen/fix-recorder-window-callback-null-menu-crash-v2 branch 2 times, most recently from 4e5751e to 3a633c5 Compare March 9, 2026 16:03
Move FixedWindowCallback from dd-sdk-android-rum to dd-sdk-android-internal
(package com.datadog.android.internal.utils) so it can be reused by
session-replay without depending on the whole RUM module.
@nguyexua
nguyexua force-pushed the lan.nguyen/fix-recorder-window-callback-null-menu-crash-v2 branch from 3a633c5 to 442230c Compare March 9, 2026 16:10

@ambushwork ambushwork left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Well done!

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the lan.nguyen/fix-recorder-window-callback-null-menu-crash-v2 branch March 10, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants