Skip to content

fix: prevent NPE crash on KYC date of birth picker#2022

Open
ayuxsh009 wants to merge 1 commit into
openMF:devfrom
ayuxsh009:fix/kyc-dob-null-crash
Open

fix: prevent NPE crash on KYC date of birth picker#2022
ayuxsh009 wants to merge 1 commit into
openMF:devfrom
ayuxsh009:fix/kyc-dob-null-crash

Conversation

@ayuxsh009

@ayuxsh009 ayuxsh009 commented May 10, 2026

Copy link
Copy Markdown

Description

What's the problem?

The KYC Level 1 date of birth picker used a non-null assertion (!!) on selectedDateMillis. During rapid taps or recomposition while the AnimatedVisibility animation was running, the value could temporarily become null even though the confirm button remained enabled, causing a NullPointerException crash.

What's the fix?

Fixes #2021
Replaced the unsafe non-null assertion with a safe ?.let call so the action is skipped safely if the selected date becomes null at tap time.

Changes

  • KYCLevel1Screen.kt — replaced unsafe !! with safe null handling on DOB confirmation
  • KYCLevel1ViewModelTest.kt — added 7 unit tests covering DobChanged flow
  • TestFakes.kt — added fake repositories for ViewModel testing
  • build.gradle.kts — added Turbine dependency for Flow testing

Testing

  • All 7 unit tests pass successfully on the desktop target
  • Verified that rapid interactions with the DOB picker no longer crash the app

  • 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.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed a crash in the date-of-birth picker that occurred when confirming without selecting a date.
  • Tests

    • Added comprehensive unit tests for KYC level 1 form functionality, covering DOB formatting, field validation, error messaging, data persistence, and dialog state management.

Review Change Stack

@ayuxsh009 ayuxsh009 requested a review from a team May 10, 2026 08:59
@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 74526dbc-ae9c-4b4d-89cc-9a72fc7f3ad1

📥 Commits

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

📒 Files selected for processing (4)
  • feature/kyc/build.gradle.kts
  • feature/kyc/src/commonMain/kotlin/org/mifospay/feature/kyc/KYCLevel1Screen.kt
  • feature/kyc/src/commonTest/kotlin/org/mifospay/feature/kyc/KYCLevel1ViewModelTest.kt
  • feature/kyc/src/commonTest/kotlin/org/mifospay/feature/kyc/TestFakes.kt

📝 Walkthrough

Walkthrough

This PR addresses a null-pointer crash in the KYC Level 1 date-of-birth picker, fixes the vulnerable confirm handler with null-safe binding, and introduces a comprehensive test suite with in-memory repository fakes to validate ViewModel behavior across initialization, validation, state loading, and dialog lifecycle scenarios.

Changes

KYC Level 1 ViewModel Testing & Crash Fix

Layer / File(s) Summary
Null-Safe Bug Fix
feature/kyc/src/commonMain/kotlin/org/mifospay/feature/kyc/KYCLevel1Screen.kt
DOB picker confirm button replaces forced unwrapping (!!) with null-safe let binding to prevent crash when selectedDateMillis becomes null during recomposition or rapid interaction.
Test Dependencies
feature/kyc/build.gradle.kts
Adds libs.turbine as a commonTest dependency to enable Flow testing in the ViewModel test suite.
Test Doubles
feature/kyc/src/commonTest/kotlin/org/mifospay/feature/kyc/TestFakes.kt
Introduces FakeKycLevelRepository (configurable KYC data with error toggle) and FakeUserPreferencesRepository (stub user identity and token flows) for isolated ViewModel testing without real persistence or network calls.
Test Infrastructure
feature/kyc/src/commonTest/kotlin/org/mifospay/feature/kyc/KYCLevel1ViewModelTest.kt (setup/imports/class declaration)
Establishes test harness: swaps main dispatcher with StandardTestDispatcher, initializes fakes, provides createViewModel() factory, and manages lifecycle with @BeforeTest setup and @AfterTest teardown.
Test Cases
feature/kyc/src/commonTest/kotlin/org/mifospay/feature/kyc/KYCLevel1ViewModelTest.kt (test methods)
Seven tests validate DOB input formatting, initial empty state, missing-field error messages (first name, DOB), loading and population of existing KYC details, handling of absent data, and dialog state clearing after dismissal.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A date picker once fell with a crash,
When null made the logic turn to ash.
With let now we bind, and fakes validate true—
Test doubles dance softly, the ViewModel shines through!
No more is the whimper of NullPointerException blue.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: prevent NPE crash on KYC date of birth picker' directly and specifically describes the primary change—fixing a NullPointerException in the date of birth picker validation.
Linked Issues check ✅ Passed The PR fully addresses issue #2021 by replacing unsafe !! with safe ?.let null handling in KYCLevel1Screen.kt, and adds comprehensive test coverage via KYCLevel1ViewModelTest.kt and TestFakes.kt.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the NPE crash and supporting test infrastructure; no unrelated modifications are present in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

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] Prevent NullPointerException crash in KYC Level 1 DOB confirmation flow

1 participant