Skip to content

fix: replace non-growable List.empty() with [] literal to prevent Uns…#1050

Open
vibhutomer wants to merge 1 commit into
mosip:masterfrom
vibhutomer:fix/fixed-length-list-crash
Open

fix: replace non-growable List.empty() with [] literal to prevent Uns…#1050
vibhutomer wants to merge 1 commit into
mosip:masterfrom
vibhutomer:fix/fixed-length-list-crash

Conversation

@vibhutomer
Copy link
Copy Markdown

@vibhutomer vibhutomer commented May 12, 2026

Description

This PR resolves a hidden runtime crash risk caused by the default behavior of Dart's List.empty().

In several service implementations, List.empty() was used to initialize lists or as a fallback return value in catch blocks. Because List.empty() defaults to growable: false, any subsequent attempt by the UI or providers to append items (.add()) to these fallback lists would result in an immediate UnsupportedError (Cannot add to a fixed-length list).

Changes Made

  • Replaced instances of List.empty() with the standard growable list literal [] in biometrics_service_impl.dart and process_spec_service_impl.dart.
  • This ensures that fallback lists returned during network or platform failures can be safely interacted with by the UI without throwing exceptions.

Related Issue

Closes #1049

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Stability improvement (prevents runtime collection errors)

Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • My changes generate no new warnings or exceptions.

Summary by CodeRabbit

  • Refactor
    • Internal code optimizations for improved consistency across the codebase. No user-facing changes.

Review Change Stack

…upportedError

Signed-off-by: vibhutomer <vibhutomer25@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Walkthrough

This PR replaces fixed-length List.empty() initializations with growable list literals ([]) across two Android platform service implementations (BiometricsServiceImpl and ProcessSpecServiceImpl). This prevents UnsupportedError crashes when consuming UI code attempts to add items to these fallback empty lists after API failures.

Changes

List Initialization Safety

Layer / File(s) Summary
BiometricsServiceImpl device list initialization
lib/platform_android/biometrics_service_impl.dart
getListOfDevices initializes deviceList using growable [] instead of fixed-length List.empty().
ProcessSpecServiceImpl fallback list initializations
lib/platform_android/process_spec_service_impl.dart
getNewProcessSpec, getOptionalLanguageCodes, and getSettingSpec replace List.empty() with growable [] in error handling and fallback paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Lists that couldn't grow were causing strife,
With crashes when you tried to add new life,
But [] brings flexibility and grace,
Now empty fallbacks find their proper place!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically describes the main change: replacing non-growable List.empty() with [] literals to prevent UnsupportedError.
Linked Issues check ✅ Passed The PR changes in biometrics_service_impl.dart and process_spec_service_impl.dart directly address issue #1049 by replacing List.empty() with [] in fallback error handling paths.
Out of Scope Changes check ✅ Passed All changes are directly related to replacing List.empty() with [] in the two specified files; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/platform_android/process_spec_service_impl.dart`:
- Around line 21-23: getMandatoryLanguageCodes() still returns a fixed-length
empty list via List.empty() in its exception/fallback paths which causes
UnsupportedError when callers try to mutate it; replace those List.empty()
returns with a growable list (e.g., use [] or List.empty(growable: true) or
List.from([])) in the exception branches inside getMandatoryLanguageCodes() so
callers can safely modify the fallback list.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d51602cc-867c-4a82-a893-abe3cc0c5169

📥 Commits

Reviewing files that changed from the base of the PR and between aef4fb6 and 945298f.

📒 Files selected for processing (2)
  • lib/platform_android/biometrics_service_impl.dart
  • lib/platform_android/process_spec_service_impl.dart

Comment on lines +21 to +23
listOfProcesses = [];
} catch (e) {
listOfProcesses = List.empty();
listOfProcesses = [];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix is still partial: one fallback path remains fixed-length.

getMandatoryLanguageCodes() still uses List.empty() in exception paths (Line 61, Line 63), so the same UnsupportedError can still occur when consumers mutate the returned fallback list.

Suggested patch
   Future<List<String?>> getMandatoryLanguageCodes() async {
     List<String?> mandatoryLanguageCodes;
     try {
       mandatoryLanguageCodes = await ProcessSpecApi().getMandatoryLanguageCodes();
     } on PlatformException {
       debugPrint("Process Spec Api failed!");
-      mandatoryLanguageCodes = List.empty();
+      mandatoryLanguageCodes = [];
     }  catch (e) {
-      mandatoryLanguageCodes = List.empty();
+      mandatoryLanguageCodes = [];
       debugPrint("Process spec fetch error: $e");
     }
     return mandatoryLanguageCodes;
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/platform_android/process_spec_service_impl.dart` around lines 21 - 23,
getMandatoryLanguageCodes() still returns a fixed-length empty list via
List.empty() in its exception/fallback paths which causes UnsupportedError when
callers try to mutate it; replace those List.empty() returns with a growable
list (e.g., use [] or List.empty(growable: true) or List.from([])) in the
exception branches inside getMandatoryLanguageCodes() so callers can safely
modify the fallback list.

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.

UnsupportedError crash due to fixed-length List.empty() initialization in Service implementations

1 participant