Skip to content

fix: prevent NPE crash in FastMpay bank mismatch and amount confirmation sheets#2024

Open
ayuxsh009 wants to merge 1 commit into
openMF:devfrom
ayuxsh009:fix/fastmpay-npe-null-state-crash
Open

fix: prevent NPE crash in FastMpay bank mismatch and amount confirmation sheets#2024
ayuxsh009 wants to merge 1 commit into
openMF:devfrom
ayuxsh009:fix/fastmpay-npe-null-state-crash

Conversation

@ayuxsh009
Copy link
Copy Markdown

Description

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

Because bankMismatchData and pendingAmountConfirmation are mutable var Compose states, recomposition could occur between the null check and the !! dereference, causing the value to become null mid-execution and resulting in a NullPointerException.

Affected Scenarios

  • Scanning a QR code from a different bank → bank mismatch bottom sheet
  • Scanning a QR code with a pre-filled amount → amount confirmation sheet

Fix

Fixes #2023
Replaced unsafe !! assertions by snapshotting nullable mutable state into local immutable val variables before the conditional checks.

This allows Kotlin smart casts to safely guarantee non-null values inside the block and removes the need for !!.

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

// After (safe)
val mismatchData = bankMismatchData
if (showBankMismatchSheet && mismatchData != null) {
    // smart cast — no !! needed
}

Changes

  • FastMpayScreen.kt

    • Replaced 2 unsafe !! assertions with safe local val snapshots

Testing

  • All existing unit tests pass:

    • FastMpayProcessorTest × 15
    • FastMpayViewModelTest × 9

Platforms Affected

  • Android
  • Desktop
  • Web

(all Compose targets)

  • Apply the AndroidStyle.xml style template to your code in Android Studio.

  • Run the unit tests with ./gradlew check to make sure you didn't break anything

  • If you have multiple commits please combine them into one commit by squashing them.

@ayuxsh009 ayuxsh009 requested a review from a team May 10, 2026 09:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

Warning

Rate limit exceeded

@ayuxsh009 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 9 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e68872e8-fea8-4896-88c8-060769c0cb6c

📥 Commits

Reviewing files that changed from the base of the PR and between d399e0a and ee09ef2.

📒 Files selected for processing (1)
  • feature/fast-mpay/src/commonMain/kotlin/org/mifospay/feature/fastmpay/FastMpayScreen.kt
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@niyajali
Copy link
Copy Markdown
Collaborator

Hi, @ayuxsh009 We appreciate your Pull Request. To facilitate seamless integration and collaboration, please ensure you have joined our Slack workspace and the relevant designated channel. We recommend thoroughly reviewing the bookmark pages, project README, and wiki to gain a comprehensive understanding of the project architecture and development guidelines. Active participation in the daily stand-up meetings is encouraged for discussions, ticket assignments, and to foster connections with the development team. Prior to requesting an assignment in the channel, please create a Jira ticket or ask for an assignment of existing tickets. All pull request descriptions must comprehensively detail the before and after changes, substantiated by relevant video or image evidence.

@ayuxsh009
Copy link
Copy Markdown
Author

Hi @niyajali, thank you for the guidance. I’ll create a Jira ticket for the issue and follow the proper contribution process for future work. Looking forward to contributing more.

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

Successfully merging this pull request may close these issues.

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

2 participants