Fix NPE in xml parser

This commit is contained in:
James Agnew 2019-11-04 09:49:33 -05:00
parent 9c93d5d7f7
commit 0b9f921c3e
3 changed files with 26 additions and 2 deletions

View File

@ -446,9 +446,10 @@ public class XmlParser extends BaseParser {
if (isBlank(extensionUrl)) {
ParseLocation loc = new ParseLocation(theEncodeContext.toString());
getErrorHandler().missingRequiredElement(loc, "url");
} else {
theEventWriter.writeAttribute("url", extensionUrl);
}
theEventWriter.writeAttribute("url", extensionUrl);
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue, childName, childDef, null, theContainedResource, nextChildElem, theEncodeContext);
theEventWriter.writeEndElement();
}
@ -610,7 +611,9 @@ public class XmlParser extends BaseParser {
}
String url = getExtensionUrl(next.getUrl());
theEventWriter.writeAttribute("url", url);
if (isNotBlank(url)) {
theEventWriter.writeAttribute("url", url);
}
if (next.getValue() != null) {
IBaseDatatype value = next.getValue();

View File

@ -109,6 +109,23 @@ public class XmlParserDstu3Test {
}
@Test
public void testEncodeExtensionWithNullUrl() {
{
Patient p = new Patient();
p.addExtension().setValue(new StringType("foo"));
String encoded = ourCtx.newXmlParser().encodeResourceToString(p);
assertEquals("<Patient xmlns=\"http://hl7.org/fhir\"><extension><valueString value=\"foo\"/></extension></Patient>", encoded);
}
{
Patient p = new Patient();
p.getActiveElement().addExtension().setValue(new StringType("foo"));
String encoded = ourCtx.newXmlParser().encodeResourceToString(p);
assertEquals("<Patient xmlns=\"http://hl7.org/fhir\"><active><extension><valueString value=\"foo\"/></extension></active></Patient>", encoded);
}
}
@Test
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
String refVal = "http://my.org/FooBar";

View File

@ -497,6 +497,10 @@
hierarchy of supported resource types, instead of just using the root resource for each type.
Thanks to Stig Døssing for the pull request!
</action>
<action type="fix">
A NullPointerException in the XML Parser was fixed when serializing a resource containing an extension
on a primitive datatype that was missing a URL declaration.
</action>
</release>
<release version="4.0.3" date="2019-09-03" description="Igloo (Point Release)">
<action type="fix">