Skip to content

fix: resolve null assertion crashes and correct API mapping in Networ…#1041

Open
vibhutomer wants to merge 1 commit into
mosip:masterfrom
vibhutomer:fix/network-service-crashes
Open

fix: resolve null assertion crashes and correct API mapping in Networ…#1041
vibhutomer wants to merge 1 commit into
mosip:masterfrom
vibhutomer:fix/network-service-crashes

Conversation

@vibhutomer
Copy link
Copy Markdown

@vibhutomer vibhutomer commented May 9, 2026

Description

This PR resolves two high-priority bugs in NetworkServiceImpl that lead to data corruption and potential runtime crashes.

Changes Made

  • Corrected API Mapping: Fixed a copy-paste error in saveScreenHeaderToGlobalParam where it was incorrectly invoking saveVersionToGlobalParam. It now routes to the proper screen header API to prevent overwriting version data.
  • Removed Unsafe Null Assertion: In getVersionNoApp(), removed the strict bang operator (!) when parsing the build['version'] map. Replaced it with a null-aware operator (?? 'Unknown') to ensure the app does not crash with a TypeError if the backend omits the version key.

Related Issue

Closes #1040

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings or exceptions.

Summary by CodeRabbit

  • Bug Fixes
    • Improved null-safety handling in version retrieval to prevent potential crashes
    • Corrected error logging messages for better debugging clarity

Review Change Stack

…kService

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

coderabbitai Bot commented May 9, 2026

Walkthrough

Two targeted safety improvements to network service error handling: getVersionNoApp() now safely defaults missing version keys to 'Unknown' using null-coalescing instead of crashing with a non-null assertion, and saveScreenHeaderToGlobalParam() updates its exception logging message to accurately reflect the operation being performed.

Changes

Network Service Safety Improvements

Layer / File(s) Summary
Version Lookup Safety
lib/platform_android/network_service_impl.dart
getVersionNoApp() replaces the crash-prone non-null assertion (!) with a null-coalescing operator, defaulting to 'Unknown' when actuatorInfo.build['version'] is missing.
Error Message Clarity
lib/platform_android/network_service_impl.dart
saveScreenHeaderToGlobalParam() updates the generic exception log from "Save version failed" to "Save screen header failed" for accurate operation labeling.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A hop through the code so small and so neat,
Null safety and clarity, a fix so sweet!
No more crashes, no more confusion,
Screen headers saved from data's delusion,
A robust app hops on, no more fear! 🌟

🚥 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 title 'fix: resolve null assertion crashes and correct API mapping in Networ…' accurately describes both main changes: fixing null assertion crashes and correcting API mapping issues in NetworkServiceImpl.
Linked Issues check ✅ Passed The pull request addresses both requirements from issue #1040: it removes the unsafe null assertion in getVersionNoApp using a null-aware fallback operator, and it corrects the API mapping in saveScreenHeaderToGlobalParam to invoke the proper screen header method.
Out of Scope Changes check ✅ Passed All code changes are directly aligned with the requirements in issue #1040; no unrelated or out-of-scope modifications are present in the pull request.
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/platform_android/network_service_impl.dart (1)

84-90: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

saveScreenHeaderToGlobalParam still calls the wrong API and can overwrite version data

Line 87 still invokes saveVersionToGlobalParam, so this method does not satisfy the fix objective and can corrupt global params. Also, Line 89’s PlatformException message still references the version API, which will mislead debugging.

Proposed fix
   `@override`
   Future<String> saveScreenHeaderToGlobalParam(String id, String value) async {
     String response = "";
     try {
-      response = await CommonDetailsApi().saveVersionToGlobalParam(id, value);
+      response =
+          await CommonDetailsApi().saveScreenHeaderToGlobalParam(id, value);
     } on PlatformException {
-      debugPrint('SaveVersionToGlobalParam Api Call Failed');
+      debugPrint('SaveScreenHeaderToGlobalParam Api Call Failed');
     } catch (e) {
       debugPrint('Save screen header failed: $e');
     }
     return response;
   }
🤖 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/network_service_impl.dart` around lines 84 - 90, The
saveScreenHeaderToGlobalParam method is still calling
CommonDetailsApi().saveVersionToGlobalParam and logs a PlatformException message
referencing the version API; change the API call to the correct endpoint (e.g.,
CommonDetailsApi().saveScreenHeaderToGlobalParam or the intended method name)
and update the PlatformException debugPrint string to refer to the screen
header/global param API so it no longer overwrites version data or misleads
debugging; ensure the method name saveScreenHeaderToGlobalParam and the
CommonDetailsApi call are consistent and return the response as before.
🤖 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.

Outside diff comments:
In `@lib/platform_android/network_service_impl.dart`:
- Around line 84-90: The saveScreenHeaderToGlobalParam method is still calling
CommonDetailsApi().saveVersionToGlobalParam and logs a PlatformException message
referencing the version API; change the API call to the correct endpoint (e.g.,
CommonDetailsApi().saveScreenHeaderToGlobalParam or the intended method name)
and update the PlatformException debugPrint string to refer to the screen
header/global param API so it no longer overwrites version data or misleads
debugging; ensure the method name saveScreenHeaderToGlobalParam and the
CommonDetailsApi call are consistent and return the response as before.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8f1f7c40-d7f7-4909-a523-92eb359b6898

📥 Commits

Reviewing files that changed from the base of the PR and between aef4fb6 and 04240c7.

📒 Files selected for processing (1)
  • lib/platform_android/network_service_impl.dart

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.

Silent failures and null-assertion crashes in NetworkServiceImpl

1 participant