New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources with null extensions causes NullPointerException when encoding to XML/JSON #312

Closed
steve1medix opened this Issue Mar 6, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@steve1medix

steve1medix commented Mar 6, 2016

When nulls are inadvertently added to a Resource extension list, a NullPointerException is triggered when encoding the Resource to XML/JSON.

This happens when using org.hl7.fhir.convertors.CCDAConverter. Line 307 for example:

pat.getExtension().add(Factory.newExtension(CcdaExtensions.NAME_RELIGION, convert.makeCodeableConceptFromCD(cda.getChild(p, "religiousAffiliationCode")), false));

Factory.newExtension occasionally returns null. When the Resource is encoded to XML/JSON, a NullPointerException is triggered.

Here's a test code (in Groovy):

def thePatient = new Patient()
thePatient.getExtension().add(null) // Purposely add null
thePatient.getExtension().add(new Extension("http://hello.world", new StringType("Hello World")))

def theCtx = FhirContext.forDstu3()
def theParser = theCtx.newXmlParser()
def theXML = theParser.encodeResourceToString(thePatient)

Here's the stacktrace:

NullPointerException occurred when processing request: ...
Stacktrace follows:
Message: null
    Line | Method
->>   77 | addUndeclaredExtensions            in ca.uhn.fhir.util.FhirTerser
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    274 | visit                              in     ''
|    111 | getAllPopulatedChildElementsOfType in     ''
|    224 | containResourcesForEncoding        in ca.uhn.fhir.parser.BaseParser
|    255 | containResourcesForEncoding . . .  in     ''
|    799 | encodeResourceToXmlStreamWriter    in ca.uhn.fhir.parser.XmlParser
|    794 | encodeResourceToXmlStreamWriter .  in     ''
|    185 | doEncodeResourceToWriter           in     ''
|    367 | encodeResourceToWriter . . . . . . in ca.uhn.fhir.parser.BaseParser
|    355 | encodeResourceToString             in     ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment