Program: 112313
Project: 112313
Buggy source:
private void encodeResourceToXmlStreamWriter(IBaseResource theResource,XMLStreamWriter theEventWriter,boolean theContainedResource,String theResourceId) throws XMLStreamException {
  if (!theContainedResource) {
    super.containResourcesForEncoding(theResource);
  }
  RuntimeResourceDefinition resDef=myContext.getResourceDefinition(theResource);
  if (resDef == null) {
    throw new ConfigurationException("String_Node_Str" + theResource.getClass());
  }
  theEventWriter.writeStartElement(resDef.getName());
  theEventWriter.writeDefaultNamespace(FHIR_NS);
  if (theResource instanceof IAnyResource) {
    encodeCompositeElementToStreamWriter(theResource,theResource,theEventWriter,resDef,theContainedResource);
  }
 else {
    if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
      IResource resource=(IResource)theResource;
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",theResourceId);
      InstantDt updated=(InstantDt)resource.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
      IdDt resourceId=resource.getId();
      if (resourceId != null && isNotBlank(resourceId.getVersionIdPart()) || (updated != null && !updated.isEmpty())) {
        theEventWriter.writeStartElement("String_Node_Str");
        String versionIdPart=resourceId.getVersionIdPart();
        if (isBlank(versionIdPart)) {
          versionIdPart=ResourceMetadataKeyEnum.VERSION.get(resource);
        }
        writeOptionalTagWithValue(theEventWriter,"String_Node_Str",versionIdPart);
        if (updated != null) {
          writeOptionalTagWithValue(theEventWriter,"String_Node_Str",updated.getValueAsString());
        }
        Object securityLabelRawObj=resource.getResourceMetadata().get(ResourceMetadataKeyEnum.SECURITY_LABELS);
        if (securityLabelRawObj != null) {
          List<BaseCodingDt> securityLabels=(List<BaseCodingDt>)securityLabelRawObj;
          if (!securityLabels.isEmpty()) {
            for (            BaseCodingDt securityLabel : securityLabels) {
              theEventWriter.writeStartElement("String_Node_Str");
              UriDt system=securityLabel.getSystemElement();
              if (system != null && !system.isEmpty())               writeOptionalTagWithValue(theEventWriter,"String_Node_Str",system.getValueAsString());
              CodeDt code=securityLabel.getCodeElement();
              if (code != null && !code.isEmpty())               writeOptionalTagWithValue(theEventWriter,"String_Node_Str",code.getValueAsString());
              StringDt display=securityLabel.getDisplayElement();
              if (display != null && !display.isEmpty())               writeOptionalTagWithValue(theEventWriter,"String_Node_Str",display.getValueAsString());
              theEventWriter.writeEndElement();
            }
          }
        }
        theEventWriter.writeEndElement();
      }
      if (theResource instanceof BaseBinary) {
        BaseBinary bin=(BaseBinary)theResource;
        writeOptionalTagWithValue(theEventWriter,"String_Node_Str",bin.getContentType());
        writeOptionalTagWithValue(theEventWriter,"String_Node_Str",bin.getContentAsBase64());
      }
 else {
        encodeResourceToStreamWriterInDstu2Format(resDef,theResource,theResource,theEventWriter,resDef,theContainedResource);
      }
    }
 else {
      if (theResourceId != null && theContainedResource) {
        theEventWriter.writeAttribute("String_Node_Str",theResourceId);
      }
      if (theResource instanceof BaseBinary) {
        BaseBinary bin=(BaseBinary)theResource;
        if (bin.getContentType() != null) {
          theEventWriter.writeAttribute("String_Node_Str",bin.getContentType());
        }
        theEventWriter.writeCharacters(bin.getContentAsBase64());
      }
 else {
        encodeCompositeElementToStreamWriter(theResource,theResource,theEventWriter,resDef,theContainedResource);
      }
    }
  }
  theEventWriter.writeEndElement();
}

Fixed version (ground truth):
private void encodeResourceToXmlStreamWriter(IBaseResource theResource,XMLStreamWriter theEventWriter,boolean theContainedResource,String theResourceId) throws XMLStreamException {
  if (!theContainedResource) {
    super.containResourcesForEncoding(theResource);
  }
  RuntimeResourceDefinition resDef=myContext.getResourceDefinition(theResource);
  if (resDef == null) {
    throw new ConfigurationException("String_Node_Str" + theResource.getClass());
  }
  theEventWriter.writeStartElement(resDef.getName());
  theEventWriter.writeDefaultNamespace(FHIR_NS);
  if (theResource instanceof IAnyResource) {
    encodeCompositeElementToStreamWriter(theResource,theResource,theEventWriter,resDef,theContainedResource);
  }
 else {
    if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
      IResource resource=(IResource)theResource;
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",theResourceId);
      InstantDt updated=(InstantDt)resource.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
      List<BaseCodingDt> securityLabels=(List<BaseCodingDt>)resource.getResourceMetadata().get(ResourceMetadataKeyEnum.SECURITY_LABELS);
      IdDt resourceId=resource.getId();
      if (resourceId != null && isNotBlank(resourceId.getVersionIdPart()) || (updated != null && !updated.isEmpty()) || (securityLabels != null && !securityLabels.isEmpty())) {
        theEventWriter.writeStartElement("String_Node_Str");
        String versionIdPart=resourceId.getVersionIdPart();
        if (isBlank(versionIdPart)) {
          versionIdPart=ResourceMetadataKeyEnum.VERSION.get(resource);
        }
        writeOptionalTagWithValue(theEventWriter,"String_Node_Str",versionIdPart);
        if (updated != null) {
          writeOptionalTagWithValue(theEventWriter,"String_Node_Str",updated.getValueAsString());
        }
        if (securityLabels != null) {
          if (!securityLabels.isEmpty()) {
            for (            BaseCodingDt securityLabel : securityLabels) {
              theEventWriter.writeStartElement("String_Node_Str");
              UriDt system=securityLabel.getSystemElement();
              if (system != null && !system.isEmpty())               writeOptionalTagWithValue(theEventWriter,"String_Node_Str",system.getValueAsString());
              CodeDt code=securityLabel.getCodeElement();
              if (code != null && !code.isEmpty())               writeOptionalTagWithValue(theEventWriter,"String_Node_Str",code.getValueAsString());
              StringDt display=securityLabel.getDisplayElement();
              if (display != null && !display.isEmpty())               writeOptionalTagWithValue(theEventWriter,"String_Node_Str",display.getValueAsString());
              theEventWriter.writeEndElement();
            }
          }
        }
        theEventWriter.writeEndElement();
      }
      if (theResource instanceof BaseBinary) {
        BaseBinary bin=(BaseBinary)theResource;
        writeOptionalTagWithValue(theEventWriter,"String_Node_Str",bin.getContentType());
        writeOptionalTagWithValue(theEventWriter,"String_Node_Str",bin.getContentAsBase64());
      }
 else {
        encodeResourceToStreamWriterInDstu2Format(resDef,theResource,theResource,theEventWriter,resDef,theContainedResource);
      }
    }
 else {
      if (theResourceId != null && theContainedResource) {
        theEventWriter.writeAttribute("String_Node_Str",theResourceId);
      }
      if (theResource instanceof BaseBinary) {
        BaseBinary bin=(BaseBinary)theResource;
        if (bin.getContentType() != null) {
          theEventWriter.writeAttribute("String_Node_Str",bin.getContentType());
        }
        theEventWriter.writeCharacters(bin.getContentAsBase64());
      }
 else {
        encodeCompositeElementToStreamWriter(theResource,theResource,theEventWriter,resDef,theContainedResource);
      }
    }
  }
  theEventWriter.writeEndElement();
}