Skip to content

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

Description

@rtmalikian

Problem

ValidateController.ProcessResource() at line 74 has the same null-dereference pattern as #5114 (ParameterCompatibleFilter.ParseResource()):

resource = parameterResource.Parameter.Find(param => param.Name.Equals("resource", StringComparison.OrdinalIgnoreCase)).Resource;

If .Find() returns null (no "resource" parameter exists), accessing .Resource throws NullReferenceException.

Additionally, line 60 does not null-check parameterResource.Parameter:

var profileFromParameters = parameterResource.Parameter.Find(param => ...);

Root Cause

No null-safety on the result of .Find() or on the Parameter collection itself. The Copilot PR #5115 fixes this in ParameterCompatibleFilter.cs but the same pattern exists in ValidateController.ProcessResource().

Proposed Fix

Add null-safety checks matching the pattern from PR #5115:

  • Null-check parameterResource.Parameter before calling .Find()
  • Null-check the .Find() result before accessing .Resource

Affected File

  • src/Microsoft.Health.Fhir.Shared.Api/Controllers/ValidateController.cs lines 60, 74

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions