fix: add null-safety checks in ValidateController.ProcessResource() (Fixes #5627)#5628
Open
rtmalikian wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5627
Summary
Adds null-safety checks in
ValidateController.ProcessResource()to preventNullReferenceExceptionwhen 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(...).Resourcewithout null-checking the result of.Find(). If no parameter named "resource" exists,.Find()returnsnulland accessing.ResourcethrowsNullReferenceException.Additionally,
parameterResource.Parameterwas accessed without null-checking, which would also throw if the Parameter collection itself is null.Changes
ValidateController.cs?.null-conditional operator onresource.TypeNamecheck?.null-conditional operator onparameterResource.Parameteraccess.Find(...).Resourcechain into separate null-safe steps matching the pattern from PR Fix NullReferenceException in ParameterCompatibleFilter.ParseResource() during resource validation #5115ValidateControllerTests.csGivenParametersWithNullParameterCollection_WhenValidating_ThenShouldNotThrowNullReferenceExceptionGivenParametersWithMissingResourceParameter_WhenValidating_ThenShouldNotThrowNullReferenceExceptionGivenParametersWithNullResourceParameter_WhenValidating_ThenShouldNotThrowNullReferenceExceptionVerification
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
Files Changed
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.