Skip to content

add null-safety checks in ValidateController.ProcessResource()#5671

Open
v-rachitsh wants to merge 4 commits into
mainfrom
personal/v-rachitsh/externalPR
Open

add null-safety checks in ValidateController.ProcessResource()#5671
v-rachitsh wants to merge 4 commits into
mainfrom
personal/v-rachitsh/externalPR

Conversation

@v-rachitsh

@v-rachitsh v-rachitsh commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #5627

Related issues

AB#198060

Summary

Adds null-safety checks in ValidateController.ProcessResource() to prevent NullReferenceException when a Parameters resource is missing the expected "resource" parameter or has a null Parameter collection.

This is the same class of bug fixed in PR #5115 for ParameterCompatibleFilter.ParseResource(), but in a separate code path.

Root Cause

ProcessResource() at line 74 called .Find(...).Resource without null-checking the result of .Find(). If no parameter named "resource" exists, .Find() returns null and accessing .Resource throws NullReferenceException.

Additionally, parameterResource.Parameter was accessed without null-checking, which would also throw if the Parameter collection itself is null.

Changes

ValidateController.cs

ValidateControllerTests.cs

  • Added 3 new test cases:
    • GivenParametersWithNullParameterCollection_WhenValidating_ThenShouldNotThrowNullReferenceException
    • GivenParametersWithMissingResourceParameter_WhenValidating_ThenShouldNotThrowNullReferenceException
    • GivenParametersWithNullResourceParameter_WhenValidating_ThenShouldNotThrowNullReferenceException

Verification

Structural verification: the fix follows the exact same null-safety pattern established in PR #5115 for ParameterCompatibleFilter.cs. Each .Find() result is now checked for null before accessing .Resource.

Files Changed

  • src/Microsoft.Health.Fhir.Shared.Api/Controllers/ValidateController.cs — Added null-conditional operators and null-safe Find result handling
  • src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/ValidateControllerTests.cs — Added 3 regression tests for null Parameters edge cases

Verification

@v-rachitsh v-rachitsh added this to the FY27\Q1\2wk\2wk01 milestone Jul 13, 2026
@v-rachitsh
v-rachitsh requested a review from a team as a code owner July 13, 2026 21:12
@v-rachitsh v-rachitsh added Bug Bug bug bug. Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs No-PaaS-breaking-change No-ADR ADR not needed labels Jul 13, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.54%. Comparing base (318be27) to head (5e0a469).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5671      +/-   ##
==========================================
+ Coverage   77.51%   77.54%   +0.03%     
==========================================
  Files        1005     1005              
  Lines       36943    36946       +3     
  Branches     5601     5603       +2     
==========================================
+ Hits        28635    28649      +14     
+ Misses       6948     6936      -12     
- Partials     1360     1361       +1     

see 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug Bug bug bug. No-ADR ADR not needed No-PaaS-breaking-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: NullReferenceException in ValidateController.ProcessResource() when Parameters lacks resource param

2 participants