FHIR Chat · Java Validator Nullpointer · hapi

Stream: hapi

Topic: Java Validator Nullpointer


view this post on Zulip Patrick Werner (Dec 31 2019 at 14:32):

When validating against an IG with profiles where derivation isn't set the validator throws some null pointers here:
https://github.com/hapifhir/org.hl7.fhir.core/blob/630ab0afcba49043ff2b145217e6735baddfaba2/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java#L489

As derived.getDerivation() returns null.

view this post on Zulip Patrick Werner (Dec 31 2019 at 14:39):

I think if it getDerivation() returns null just skip the following block?

view this post on Zulip Grahame Grieve (Dec 31 2019 at 19:09):

why is derivation null?

view this post on Zulip Patrick Werner (Dec 31 2019 at 19:10):

I guess because it wasn‘t populated in the StrucDef

view this post on Zulip Patrick Werner (Dec 31 2019 at 19:11):

The StructureDefinition itself, which i parsed, does not have have it

view this post on Zulip Patrick Werner (Dec 31 2019 at 19:12):

So it ends up as Null in the Instance

view this post on Zulip Patrick Werner (Dec 31 2019 at 19:12):

Added a PR to fix it

view this post on Zulip Grahame Grieve (Dec 31 2019 at 19:17):

fix it how? how can you generate a snapshot if there's no derivation?

view this post on Zulip Patrick Werner (Jan 09 2020 at 11:07):

Sorry for the insufficient explanation last time, was on the mobile phone.
This is used in the Validator at several places: (derived.getDerivation().equals(TypeDerivationRule.SPECIALIZATION))
When you are validating against a profile which StrucDef doesn't has derivation populated a NullPointer is thrown as there is no null check and the variable derived stays null after parsing the profile.

view this post on Zulip Grahame Grieve (Jan 09 2020 at 21:37):

but why is there no derivation, and how can the SD make sense?

view this post on Zulip Patrick Werner (Jan 10 2020 at 09:49):

because derivation is 0..1 and not enforced. The parser sets derivation to null if not populated and then later throws a null pointer.

view this post on Zulip Patrick Werner (Jan 10 2020 at 09:49):

So this PR is about making these methods null-safe.

view this post on Zulip Patrick Werner (Jan 10 2020 at 09:50):

Why are you expecting StructureDefinition.derivation to be populated when it is 0..1 ?

view this post on Zulip Grahame Grieve (Jan 10 2020 at 09:56):

the only case when it shouldn't have a value is when there's no base definition. If there's a base definition, how can it be meaningful if there derivation is unknown?

view this post on Zulip Patrick Werner (Jan 10 2020 at 10:31):

i agree on a logic level, but as far as i can see a StructureDefinition with no derivation is a valid on a technical level as i can't see anything enforcing the population of the derivation. e.g.: https://simplifier.net/BasisprofilDE/organization-de-basis-0.2/~xml doesn't have it populated.

view this post on Zulip Grahame Grieve (Jan 10 2020 at 10:35):

it's valid on a technical level, but not meaningful for generating a snapshot

view this post on Zulip Patrick Werner (Jan 10 2020 at 11:48):

agree. So i'll update my PR to not default to derivation=constrain - but to catch the NullPointer and Log a meaningful error?

view this post on Zulip Grahame Grieve (Jan 10 2020 at 11:54):

I just made the change here after our discussion.

view this post on Zulip Patrick Werner (Jan 10 2020 at 11:57):

:+1:

view this post on Zulip Patrick Werner (Jan 10 2020 at 13:41):

can you push the change?


Last updated: Apr 12 2022 at 19:14 UTC