Skip to content

fix: NPE in getSDKScore() when SDK omits modality from quality map#790

Open
ayuxsh009 wants to merge 1 commit into
mosip:masterfrom
ayuxsh009:fix/sdk-score-npe
Open

fix: NPE in getSDKScore() when SDK omits modality from quality map#790
ayuxsh009 wants to merge 1 commit into
mosip:masterfrom
ayuxsh009:fix/sdk-score-npe

Conversation

@ayuxsh009
Copy link
Copy Markdown

@ayuxsh009 ayuxsh009 commented May 14, 2026

Summary

Fixes a NullPointerException in BioServiceImpl.getSDKScore() when
the SDK does not return a quality score entry for the requested
BiometricType.

Root Cause

scoreMap.get(biometricType) was directly auto-unboxed to double.

If the SDK returned a map without the requested modality key,
get() returned null, causing a NullPointerException
during unboxing.

The exception bypassed the biometric error handling flow and was
eventually surfaced as MDS_RCAPTURE_ERROR.

Fix #789

Added a null check before unboxing the score value.

If the modality score is absent, the method now throws a
BiometricException with error code SDK_SCORE_NULL
instead of allowing an unchecked NullPointerException.

Float score = scoreMap.get(biometricType);

if (score == null) {
    throw new BiometricException(
        "SDK_SCORE_NULL",
        "SDK did not return quality score for " + biometricType
    );
}

return score.doubleValue();

Tests Added

Added regression test cases for:

  • missing modality key in SDK response map
  • empty SDK response map

Both tests verify that BiometricException
is thrown instead of NullPointerException.

Files Changed

  • BioServiceImpl.java
  • BioServiceTest.java

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced biometric quality score validation with explicit error handling for missing or invalid quality data.
  • Tests

    • Added test coverage for biometric quality score exception scenarios.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Walkthrough

The PR adds null-safety validation to BioServiceImpl.getSDKScore(), which now explicitly checks that the bio provider's quality score exists for the requested modality before returning it. If the score is missing, a BiometricException is thrown with a specific error code. Two unit tests verify this exception handling for missing modality keys and empty maps.

Changes

SDK Score Null-Safety Check

Layer / File(s) Summary
Score null-check and exception handling
registration/registration-services/src/main/java/io/mosip/registration/service/bio/impl/BioServiceImpl.java
getSDKScore extracts the Float score from scoreMap, validates it is not null, and throws BiometricException if the modality is missing; otherwise returns the score as double via doubleValue().
Missing modality and empty map exception tests
registration/registration-services/src/test/java/io/mosip/registration/bio/service/test/BioServiceTest.java
Two tests mock the SDK quality map to omit the FACE key and to be empty, asserting that bioService.getSDKScore throws BiometricException in both scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Poem

🐰 A score that vanishes in the map?
No more—we catch it with a trap!
Null checks leap forward, tests align,
Bio scores safe, by design. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main fix: adding a null pointer exception handler for the getSDKScore() method when a biometric modality is omitted from the quality map.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Signed-off-by: ayuxsh009 <1raj.aayush@gmail.com>
@ayuxsh009 ayuxsh009 force-pushed the fix/sdk-score-npe branch from 1b94e95 to 40fb8ba Compare May 14, 2026 17:12
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.

[BUG] NullPointerException in BioServiceImpl.getSDKScore() when SDK omits modality key from quality score map

1 participant