Program: 112272
Project: 112272
Buggy source:
private <R extends IBaseResource>R populateResourceMetadataHapi(Class<R> theResourceType,BaseHasResource theEntity,boolean theForHistoryOperation,IResource res){
  R retVal=(R)res;
  if (theEntity.getDeleted() != null) {
    res=(IResource)myContext.getResourceDefinition(theResourceType).newInstance();
    retVal=(R)res;
    ResourceMetadataKeyEnum.DELETED_AT.put(res,new InstantDt(theEntity.getDeleted()));
    if (theForHistoryOperation) {
      ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res,BundleEntryTransactionMethodEnum.DELETE);
    }
  }
 else   if (theForHistoryOperation) {
    Date published=theEntity.getPublished().getValue();
    Date updated=theEntity.getUpdated().getValue();
    if (published.equals(updated)) {
      ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res,BundleEntryTransactionMethodEnum.POST);
    }
 else {
      ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res,BundleEntryTransactionMethodEnum.PUT);
    }
  }
  res.setId(theEntity.getIdDt());
  ResourceMetadataKeyEnum.VERSION.put(res,Long.toString(theEntity.getVersion()));
  ResourceMetadataKeyEnum.PUBLISHED.put(res,theEntity.getPublished());
  ResourceMetadataKeyEnum.UPDATED.put(res,theEntity.getUpdated());
  IDao.RESOURCE_PID.put(res,theEntity.getId());
  if (theEntity.getTitle() != null) {
    ResourceMetadataKeyEnum.TITLE.put(res,theEntity.getTitle());
  }
  Collection<? extends BaseTag> tags=theEntity.getTags();
  if (theEntity.isHasTags()) {
    TagList tagList=new TagList();
    List<IBaseCoding> securityLabels=new ArrayList<IBaseCoding>();
    List<IdDt> profiles=new ArrayList<IdDt>();
    for (    BaseTag next : tags) {
switch (next.getTag().getTagType()) {
case PROFILE:
        profiles.add(new IdDt(next.getTag().getCode()));
      break;
case SECURITY_LABEL:
    IBaseCoding secLabel=(IBaseCoding)myContext.getVersion().newCodingDt();
  secLabel.setSystem(next.getTag().getSystem());
secLabel.setCode(next.getTag().getCode());
secLabel.setDisplay(next.getTag().getDisplay());
securityLabels.add(secLabel);
break;
case TAG:
tagList.add(new Tag(next.getTag().getSystem(),next.getTag().getCode(),next.getTag().getDisplay()));
break;
}
}
if (tagList.size() > 0) {
ResourceMetadataKeyEnum.TAG_LIST.put(res,tagList);
}
if (securityLabels.size() > 0) {
ResourceMetadataKeyEnum.SECURITY_LABELS.put(res,toBaseCodingList(securityLabels));
}
if (profiles.size() > 0) {
ResourceMetadataKeyEnum.PROFILES.put(res,profiles);
}
}
return retVal;
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") private <R extends IBaseResource>R populateResourceMetadataHapi(Class<R> theResourceType,BaseHasResource theEntity,boolean theForHistoryOperation,IResource res){
  R retVal=(R)res;
  if (theEntity.getDeleted() != null) {
    res=(IResource)myContext.getResourceDefinition(theResourceType).newInstance();
    retVal=(R)res;
    ResourceMetadataKeyEnum.DELETED_AT.put(res,new InstantDt(theEntity.getDeleted()));
    if (theForHistoryOperation) {
      ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res,BundleEntryTransactionMethodEnum.DELETE);
    }
  }
 else   if (theForHistoryOperation) {
    Date published=theEntity.getPublished().getValue();
    Date updated=theEntity.getUpdated().getValue();
    if (published.equals(updated)) {
      ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res,BundleEntryTransactionMethodEnum.POST);
    }
 else {
      ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res,BundleEntryTransactionMethodEnum.PUT);
    }
  }
  res.setId(theEntity.getIdDt());
  ResourceMetadataKeyEnum.VERSION.put(res,Long.toString(theEntity.getVersion()));
  ResourceMetadataKeyEnum.PUBLISHED.put(res,theEntity.getPublished());
  ResourceMetadataKeyEnum.UPDATED.put(res,theEntity.getUpdated());
  IDao.RESOURCE_PID.put(res,theEntity.getId());
  if (theEntity.getTitle() != null) {
    ResourceMetadataKeyEnum.TITLE.put(res,theEntity.getTitle());
  }
  Collection<? extends BaseTag> tags=theEntity.getTags();
  if (theEntity.isHasTags()) {
    TagList tagList=new TagList();
    List<IBaseCoding> securityLabels=new ArrayList<IBaseCoding>();
    List<IdDt> profiles=new ArrayList<IdDt>();
    for (    BaseTag next : tags) {
switch (next.getTag().getTagType()) {
case PROFILE:
        profiles.add(new IdDt(next.getTag().getCode()));
      break;
case SECURITY_LABEL:
    IBaseCoding secLabel=(IBaseCoding)myContext.getVersion().newCodingDt();
  secLabel.setSystem(next.getTag().getSystem());
secLabel.setCode(next.getTag().getCode());
secLabel.setDisplay(next.getTag().getDisplay());
securityLabels.add(secLabel);
break;
case TAG:
tagList.add(new Tag(next.getTag().getSystem(),next.getTag().getCode(),next.getTag().getDisplay()));
break;
}
}
if (tagList.size() > 0) {
ResourceMetadataKeyEnum.TAG_LIST.put(res,tagList);
}
if (securityLabels.size() > 0) {
ResourceMetadataKeyEnum.SECURITY_LABELS.put(res,toBaseCodingList(securityLabels));
}
if (profiles.size() > 0) {
ResourceMetadataKeyEnum.PROFILES.put(res,profiles);
}
}
return retVal;
}