Skip to content

Fix: Create Savings Account crash due to invalid numeric input#2006

Open
rahul31124 wants to merge 1 commit intoopenMF:developmentfrom
rahul31124:input-validation
Open

Fix: Create Savings Account crash due to invalid numeric input#2006
rahul31124 wants to merge 1 commit intoopenMF:developmentfrom
rahul31124:input-validation

Conversation

@rahul31124
Copy link
Copy Markdown

@rahul31124 rahul31124 commented Apr 12, 2026

Issue Fix

Fixes #{MW-396}
Jira Task: MW-396

Screenshots

Record_2026-04-12-19-18-12_6a5d239ecc870d7d1b844aa672071987.mp4

Description

The Create Savings Account screen was crashing when numeric fields were empty or contained invalid values because the app was directly parsing them to Long and Double.

To fix this, safe parsing was added using toLongOrNull() and toDoubleOrNull() with default fallback values. This prevents crashes by handling empty or invalid inputs.

  • 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
    • Improved input validation for savings account opening balance and interest rate fields to gracefully handle invalid numeric entries, preventing potential application errors and ensuring a smoother user experience.

@rahul31124 rahul31124 requested a review from a team April 12, 2026 14:12
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 28403227-2e66-459a-92a6-0d57f5eb8ba9

📥 Commits

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

📒 Files selected for processing (1)
  • feature/accounts/src/commonMain/kotlin/org/mifospay/feature/accounts/savingsaccount/AddEditSavingViewModel.kt

📝 Walkthrough

Walkthrough

Updated numeric input handling in AddEditSavingViewModel to safely parse user-provided balance and interest rate values. The changes implement defensive null-coalescing for string-to-numeric conversions and normalize non-finite numeric values to sensible defaults, preventing parsing exceptions and invalid state.

Changes

Cohort / File(s) Summary
Numeric Input Validation
feature/accounts/src/commonMain/kotlin/org/mifospay/feature/accounts/savingsaccount/AddEditSavingViewModel.kt
Changed balance parsing from direct toLong() to toLongOrNull() with 0L fallback; changed rate parsing from direct toDouble() to toDoubleOrNull() with 0.0 fallback; added normalization of non-finite values (NaN/Infinity) to 0.0.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hops through balance fields,
With parsing guards that safety yields,
No more crashes from digits strange—
NaN and Infinity now all rearrange,
To zeros safe, the viewmodel sings! 🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main issue being fixed: a crash in Create Savings Account caused by invalid numeric input, matching the core change 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

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.

1 participant