Skip to content

[Bug] NullPointerException crash in FastMpayScreen due to unsafe access on mutable Compose state #2023

Description

@ayuxsh009

Description

The FastMpayScreen contains unsafe non-null assertions (!!) on nullable mutable Compose state variables inside conditional null checks.

Because these states are declared as mutable var Compose states, recomposition may occur between the null check and the !! dereference, causing the value to become null and resulting in a NullPointerException.

Location

feature/fast-mpay/src/commonMain/kotlin/org/mifospay/feature/fastmpay/FastMpayScreen.kt

Bank mismatch sheet

if (showBankMismatchSheet && bankMismatchData != null) {
    val mismatchData = bankMismatchData!! // unsafe
}

Amount confirmation sheet

if (showAmountConfirmation && pendingAmountConfirmation != null) {
    val pending = pendingAmountConfirmation!! // unsafe
}

Root Cause

bankMismatchData and pendingAmountConfirmation are mutable Compose states (var).

In Jetpack Compose, recomposition can happen between:

  1. the null check (state != null)
  2. the !! dereference

This creates a race condition where the value becomes null after the check but before dereferencing.

Steps to Reproduce

  1. Open FastMpay screen
  2. Scan a QR code from another bank (opens bank mismatch sheet)
  3. Trigger rapid recomposition/interactions while the sheet is rendering
  4. App crashes with NullPointerException

Same issue can occur for the amount confirmation sheet.

Expected Behavior

The sheet should render safely or be skipped gracefully if the state becomes null.

Actual Behavior

Application crashes with NullPointerException.

Impact

  • Affects all Compose targets:

    • Android
    • Desktop
    • Web

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions