Skip to content

fix: add null-safety checks in ValidateController.ProcessResource() (Fixes #5627)#5628

Open
rtmalikian wants to merge 1 commit into
microsoft:mainfrom
rtmalikian:fix/issue-5627-validate-controller-null-ref
Open

fix: add null-safety checks in ValidateController.ProcessResource() (Fixes #5627)#5628
rtmalikian wants to merge 1 commit into
microsoft:mainfrom
rtmalikian:fix/issue-5627-validate-controller-null-ref

Conversation

@rtmalikian

Copy link
Copy Markdown

Fixes #5627

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.

Changelog

Date Change Author
2026-06-20 Add null-safety checks in ValidateController.ProcessResource() rtmalikian

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


About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.

📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a


Disclosure: This code was developed with assistance from mimo-v2.5-pro (Xiaomi) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.

Prevent NullReferenceException when Parameters resource has:
- Null Parameter collection
- No 'resource' parameter
- 'resource' parameter with null Resource property

Matches the null-safety pattern from PR microsoft#5115 (ParameterCompatibleFilter).

Fixes microsoft#5627

Signed-off-by: rtmalikian <rtmalikian@gmail.com>
@rtmalikian rtmalikian requested a review from a team as a code owner June 20, 2026 04: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.

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

1 participant