From 9835bea27d4576508479f471b8c3909c4478345b Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 25 Nov 2024 14:21:40 +1100 Subject: [PATCH] fix NPE in validator around Extension context --- RELEASE_NOTES.md | 2 +- .../instance/InstanceValidator.java | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d4626a173..0b7ef61b8 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,6 @@ ## Validator Changes -* no changes +* fix NPE in validator around Extension context ## Other code changes diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 3880b7322..da75e0cba 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -2479,22 +2479,26 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } if (ctxt.getType() == ExtensionContextType.ELEMENT) { String en = ctxt.getExpression(); - contexts.append("e:" + en); String pu = null; - if (en.contains("#")) { - pu = en.substring(0, en.indexOf("#")); - en = en.substring(en.indexOf("#")+1); + if (en == null) { + // nothing? It's an error in the extension definition, but that's properly reported elsewhere } else { - //pu = en; - } - if (Utilities.existsInList(en, "Element", "Any")) { - ok = true; - } else if (en.equals("Resource") && container.isResource()) { - ok = true; - } else if (en.equals("CanonicalResource") && containsAny(VersionUtilities.getExtendedCanonicalResourceNames(context.getVersion()), plist)) { - ok = true; - } else if (hasElementName(plist, en) && pu == null) { - ok = true; + contexts.append("e:" + en); + if (en.contains("#")) { + pu = en.substring(0, en.indexOf("#")); + en = en.substring(en.indexOf("#")+1); + } else { + //pu = en; + } + if (Utilities.existsInList(en, "Element", "Any")) { + ok = true; + } else if (en.equals("Resource") && container.isResource()) { + ok = true; + } else if (en.equals("CanonicalResource") && containsAny(VersionUtilities.getExtendedCanonicalResourceNames(context.getVersion()), plist)) { + ok = true; + } else if (hasElementName(plist, en) && pu == null) { + ok = true; + } } if (!ok) {