fix: replace non-growable List.empty() with [] literal to prevent Uns…#1050
fix: replace non-growable List.empty() with [] literal to prevent Uns…#1050vibhutomer wants to merge 1 commit into
Conversation
…upportedError Signed-off-by: vibhutomer <vibhutomer25@gmail.com>
WalkthroughThis PR replaces fixed-length ChangesList Initialization Safety
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
lib/platform_android/biometrics_service_impl.dartlib/platform_android/process_spec_service_impl.dart
| listOfProcesses = []; | ||
| } catch (e) { | ||
| listOfProcesses = List.empty(); | ||
| listOfProcesses = []; |
There was a problem hiding this comment.
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.
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 incatchblocks. BecauseList.empty()defaults togrowable: false, any subsequent attempt by the UI or providers to append items (.add()) to these fallback lists would result in an immediateUnsupportedError (Cannot add to a fixed-length list).Changes Made
List.empty()with the standard growable list literal[]inbiometrics_service_impl.dartandprocess_spec_service_impl.dart.Related Issue
Closes #1049
Type of Change
Checklist
Summary by CodeRabbit