Program: 112310
Project: 112310
Buggy source:
private void encodeBundleToWriterDstu2(Bundle theBundle,XMLStreamWriter theEventWriter) throws XMLStreamException {
  theEventWriter.writeStartElement("String_Node_Str");
  theEventWriter.writeDefaultNamespace(FHIR_NS);
  writeOptionalTagWithValue(theEventWriter,"String_Node_Str",theBundle.getId().getIdPart());
  InstantDt updated=(InstantDt)theBundle.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
  IdDt bundleId=theBundle.getId();
  if (bundleId != null && isNotBlank(bundleId.getVersionIdPart()) || (updated != null && !updated.isEmpty())) {
    theEventWriter.writeStartElement("String_Node_Str");
    writeOptionalTagWithValue(theEventWriter,"String_Node_Str",bundleId.getVersionIdPart());
    if (updated != null) {
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",updated.getValueAsString());
    }
    theEventWriter.writeEndElement();
  }
  String bundleBaseUrl=theBundle.getLinkBase().getValue();
  writeOptionalTagWithValue(theEventWriter,"String_Node_Str",theBundle.getType().getValue());
  writeOptionalTagWithValue(theEventWriter,"String_Node_Str",bundleBaseUrl);
  writeOptionalTagWithValue(theEventWriter,"String_Node_Str",theBundle.getTotalResults().getValueAsString());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkFirst());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkPrevious());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkNext());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkLast());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkSelf());
  for (  BundleEntry nextEntry : theBundle.getEntries()) {
    theEventWriter.writeStartElement("String_Node_Str");
    boolean deleted=false;
    if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) {
      deleted=true;
    }
    writeOptionalTagWithValue(theEventWriter,"String_Node_Str",determineResourceBaseUrl(bundleBaseUrl,nextEntry));
    IResource resource=nextEntry.getResource();
    if (resource != null && !resource.isEmpty() && !deleted) {
      theEventWriter.writeStartElement("String_Node_Str");
      encodeResourceToXmlStreamWriter(resource,theEventWriter,false);
      theEventWriter.writeEndElement();
    }
 else {
      ourLog.debug("String_Node_Str");
    }
    if (nextEntry.getSearchMode().isEmpty() == false || nextEntry.getScore().isEmpty() == false) {
      theEventWriter.writeStartElement("String_Node_Str");
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getSearchMode().getValueAsString());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getScore().getValueAsString());
      theEventWriter.writeEndElement();
    }
    if (nextEntry.getTransactionOperation().isEmpty() == false || nextEntry.getLinkSearch().isEmpty() == false) {
      theEventWriter.writeStartElement("String_Node_Str");
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getTransactionOperation().getValue());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getLinkSearch().getValue());
      theEventWriter.writeEndElement();
    }
    if (deleted) {
      theEventWriter.writeStartElement("String_Node_Str");
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getId().getResourceType());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getId().getIdPart());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getId().getVersionIdPart());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getDeletedAt().getValueAsString());
      theEventWriter.writeEndElement();
    }
    theEventWriter.writeEndElement();
  }
  theEventWriter.writeEndElement();
  theEventWriter.close();
}

Fixed version (ground truth):
private void encodeBundleToWriterDstu2(Bundle theBundle,XMLStreamWriter theEventWriter) throws XMLStreamException {
  theEventWriter.writeStartElement("String_Node_Str");
  theEventWriter.writeDefaultNamespace(FHIR_NS);
  writeOptionalTagWithValue(theEventWriter,"String_Node_Str",theBundle.getId().getIdPart());
  InstantDt updated=(InstantDt)theBundle.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
  IdDt bundleId=theBundle.getId();
  if (bundleId != null && isNotBlank(bundleId.getVersionIdPart()) || (updated != null && !updated.isEmpty())) {
    theEventWriter.writeStartElement("String_Node_Str");
    writeOptionalTagWithValue(theEventWriter,"String_Node_Str",bundleId.getVersionIdPart());
    if (updated != null) {
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",updated.getValueAsString());
    }
    theEventWriter.writeEndElement();
  }
  String bundleBaseUrl=theBundle.getLinkBase().getValue();
  writeOptionalTagWithValue(theEventWriter,"String_Node_Str",theBundle.getType().getValue());
  writeOptionalTagWithValue(theEventWriter,"String_Node_Str",bundleBaseUrl);
  writeOptionalTagWithValue(theEventWriter,"String_Node_Str",theBundle.getTotalResults().getValueAsString());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkFirst());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkPrevious());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkNext());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkLast());
  writeBundleResourceLink(theEventWriter,"String_Node_Str",theBundle.getLinkSelf());
  for (  BundleEntry nextEntry : theBundle.getEntries()) {
    theEventWriter.writeStartElement("String_Node_Str");
    boolean deleted=false;
    if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) {
      deleted=true;
    }
    writeOptionalTagWithValue(theEventWriter,"String_Node_Str",determineResourceBaseUrl(bundleBaseUrl,nextEntry));
    IResource resource=nextEntry.getResource();
    if (resource != null && !resource.isEmpty() && !deleted) {
      theEventWriter.writeStartElement("String_Node_Str");
      encodeResourceToXmlStreamWriter(resource,theEventWriter,false);
      theEventWriter.writeEndElement();
    }
 else {
      ourLog.debug("String_Node_Str");
    }
    if (nextEntry.getSearchMode().isEmpty() == false || nextEntry.getScore().isEmpty() == false) {
      theEventWriter.writeStartElement("String_Node_Str");
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getSearchMode().getValueAsString());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getScore().getValueAsString());
      theEventWriter.writeEndElement();
    }
    if (nextEntry.getTransactionMethod().isEmpty() == false || nextEntry.getLinkSearch().isEmpty() == false) {
      theEventWriter.writeStartElement("String_Node_Str");
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getTransactionMethod().getValue());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getLinkSearch().getValue());
      theEventWriter.writeEndElement();
    }
    if (deleted) {
      theEventWriter.writeStartElement("String_Node_Str");
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getId().getResourceType());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getId().getIdPart());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getId().getVersionIdPart());
      writeOptionalTagWithValue(theEventWriter,"String_Node_Str",nextEntry.getDeletedAt().getValueAsString());
      theEventWriter.writeEndElement();
    }
    theEventWriter.writeEndElement();
  }
  theEventWriter.writeEndElement();
  theEventWriter.close();
}