Skip to content

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

Open
rahul31124 wants to merge 2 commits intoopenMF:developmentfrom
rahul31124:input-validation
Open

Fix: Create Savings Account crash due to invalid numeric input#2006
rahul31124 wants to merge 2 commits 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

  • Bug Fixes
    • Improved validation for savings account numeric inputs: opening balance and nominal annual interest rate now handle invalid or non-finite entries gracefully, defaulting to safe values to prevent errors and improve form stability and 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: 07e4e9f4-57bf-46c7-bed9-86bb9cab6f4d

📥 Commits

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

📒 Files selected for processing (1)
  • feature/accounts/src/commonMain/kotlin/org/mifospay/feature/accounts/savingsaccount/AddEditSavingViewModel.kt
✅ Files skipped from review due to trivial changes (1)
  • feature/accounts/src/commonMain/kotlin/org/mifospay/feature/accounts/savingsaccount/AddEditSavingViewModel.kt

📝 Walkthrough

Walkthrough

Made numeric parsing defensive in AddEditSavingViewModel: balance strings are parsed with toLongOrNull() falling back to 0L; interest rate strings are parsed with toDoubleOrNull() falling back to 0.0, with non-finite values (NaN/Infinity) normalized to 0.0. No public APIs changed.

Changes

Cohort / File(s) Summary
Numeric Input Validation
feature/accounts/src/commonMain/kotlin/org/mifospay/feature/accounts/savingsaccount/AddEditSavingViewModel.kt
Replaced direct toLong() with toLongOrNull() plus 0L fallback for balance; replaced toDouble() with toDoubleOrNull() plus 0.0 fallback for rate; treat non-finite doubles as 0.0.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I nibble strings of rate and sum,
Turn errors to zeros, safe and calm,
No crashes now when digits stray,
NaN and Infinity hop away,
Hooray—your viewmodel's snug today! 🐇✨

🚥 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 'Fix: Create Savings Account crash due to invalid numeric input' clearly and specifically describes the main change: replacing unsafe numeric parsing with safe parsing to prevent crashes when users enter invalid input in the Create Savings Account screen.

✏️ 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.

niyajali
niyajali previously approved these changes Apr 16, 2026
@niyajali niyajali enabled auto-merge (squash) April 16, 2026 03:07
auto-merge was automatically disabled April 16, 2026 16:13

Head branch was pushed to by a user without write access

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.

2 participants