From 8e0363194411c2e8124362b47b5fb7797b45f85e Mon Sep 17 00:00:00 2001 From: Max Bureck Date: Wed, 11 Dec 2024 17:26:04 +0100 Subject: [PATCH] Fixing concurrency issue in VersionSpecificWorkerContextWrapper (#6554) When validating if a code is valid against a ValueSet, a potentially cached (and therefore shared) result object was mutated. This mutation is now done on a copy of the result object. --- .../VersionSpecificWorkerContextWrapper.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java index 393d8ce1dc54..73b4d5e56cfb 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java @@ -3,6 +3,8 @@ import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.support.ConceptValidationOptions; import ca.uhn.fhir.context.support.IValidationSupport; +import ca.uhn.fhir.context.support.IValidationSupport.BaseConceptProperty; +import ca.uhn.fhir.context.support.IValidationSupport.CodeValidationIssue; import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; @@ -825,6 +827,7 @@ private IValidationSupport.CodeValidationResult validateCodeInValueSet( final boolean valueSetResultContainsInvalidDisplay = result.getIssues().stream() .anyMatch(VersionSpecificWorkerContextWrapper::hasInvalidDisplayDetailCode); if (codeSystemResult != null) { + result = copyCodeValidationResult(result); for (IValidationSupport.CodeValidationIssue codeValidationIssue : codeSystemResult.getIssues()) { /* Value set validation should already have checked the display name. If we get INVALID_DISPLAY issues from code system validation, they will only repeat what was already caught. @@ -838,6 +841,33 @@ private IValidationSupport.CodeValidationResult validateCodeInValueSet( return result; } + private IValidationSupport.CodeValidationResult copyCodeValidationResult( + IValidationSupport.CodeValidationResult toCopy) { + IValidationSupport.CodeValidationResult result = new IValidationSupport.CodeValidationResult(); + + List issues = toCopy.getIssues(); + List properties = toCopy.getProperties(); + + result.setCode(toCopy.getCode()) + .setCodeSystemName(toCopy.getCodeSystemName()) + .setCodeSystemVersion(toCopy.getCodeSystemVersion()) + .setDisplay(toCopy.getDisplay()) + .setIssues(copyList(issues)) + .setMessage(toCopy.getMessage()) + .setSeverity(toCopy.getSeverity()) + .setSourceDetails(toCopy.getSourceDetails()) + .setProperties(copyList(properties)); + return result; + } + + private List copyList(List issues) { + if (issues == null) { + return null; + } else { + return new ArrayList<>(issues); + } + } + private static boolean hasInvalidDisplayDetailCode(IValidationSupport.CodeValidationIssue theIssue) { return theIssue.hasIssueDetailCode(INVALID_DISPLAY.getCode()); }