Program: 112150
Project: 112150
Buggy source:
private void doLoadPids(List<IBaseResource> theResourceListToPopulate,Set<Long> theRevIncludedPids,boolean theForHistoryOperation,EntityManager entityManager,FhirContext context,IDao theDao,Map<Long,Integer> position,Collection<Long> pids){
  CriteriaBuilder builder=entityManager.getCriteriaBuilder();
  CriteriaQuery<ResourceTable> cq=builder.createQuery(ResourceTable.class);
  Root<ResourceTable> from=cq.from(ResourceTable.class);
  cq.where(from.get("String_Node_Str").in(pids));
  TypedQuery<ResourceTable> q=entityManager.createQuery(cq);
  List<ResourceTable> resultList=q.getResultList();
  Map<Long,ResourceHistoryTable> historyMap=getResourceHistoryMap(pids);
  Map<Long,Collection<ResourceTag>> tagMap=getResourceTagMap(resultList);
  for (  ResourceTable next : resultList) {
    Class<? extends IBaseResource> resourceType=context.getResourceDefinition(next.getResourceType()).getImplementingClass();
    IBaseResource resource=theDao.toResource(resourceType,next,historyMap.get(next.getId()),tagMap.get(next.getId()),theForHistoryOperation);
    if (resource == null) {
      ourLog.warn("String_Node_Str",next.getResourceType(),next.getIdDt().getIdPart(),next.getVersion());
      continue;
    }
    Integer index=position.get(next.getId());
    if (index == null) {
      ourLog.warn("String_Node_Str",next.getId());
      continue;
    }
    if (resource instanceof IResource) {
      if (theRevIncludedPids.contains(next.getId())) {
        ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource,BundleEntrySearchModeEnum.INCLUDE);
      }
 else {
        ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource,BundleEntrySearchModeEnum.MATCH);
      }
    }
 else {
      if (theRevIncludedPids.contains(next.getId())) {
        ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource)resource,BundleEntrySearchModeEnum.INCLUDE.getCode());
      }
 else {
        ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource)resource,BundleEntrySearchModeEnum.MATCH.getCode());
      }
    }
    theResourceListToPopulate.set(index,resource);
  }
}

Fixed version (ground truth):
private void doLoadPids(List<IBaseResource> theResourceListToPopulate,Set<Long> theRevIncludedPids,boolean theForHistoryOperation,EntityManager entityManager,FhirContext context,IDao theDao,Map<Long,Integer> position,Collection<Long> pids){
  CriteriaBuilder builder=entityManager.getCriteriaBuilder();
  CriteriaQuery<ResourceTable> cq=builder.createQuery(ResourceTable.class);
  Root<ResourceTable> from=cq.from(ResourceTable.class);
  cq.where(from.get("String_Node_Str").in(pids));
  TypedQuery<ResourceTable> q=entityManager.createQuery(cq);
  List<ResourceTable> resultList=q.getResultList();
  Map<Long,ResourceHistoryTable> historyMap=getResourceHistoryMap(pids);
  Map<Long,Collection<ResourceTag>> tagMap=getResourceTagMap(resultList);
  Map<Long,ForcedId> forcedIdMap=getForcedIdMap(pids);
  ForcedId forcedId=null;
  Long resourceId=null;
  for (  ResourceTable next : resultList) {
    Class<? extends IBaseResource> resourceType=context.getResourceDefinition(next.getResourceType()).getImplementingClass();
    resourceId=next.getId();
    forcedId=forcedIdMap.get(resourceId);
    if (forcedId != null)     next.setForcedId(forcedId);
    IBaseResource resource=theDao.toResource(resourceType,next,historyMap.get(next.getId()),tagMap.get(next.getId()),theForHistoryOperation);
    if (resource == null) {
      ourLog.warn("String_Node_Str",next.getResourceType(),next.getIdDt().getIdPart(),next.getVersion());
      continue;
    }
    Integer index=position.get(next.getId());
    if (index == null) {
      ourLog.warn("String_Node_Str",next.getId());
      continue;
    }
    if (resource instanceof IResource) {
      if (theRevIncludedPids.contains(next.getId())) {
        ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource,BundleEntrySearchModeEnum.INCLUDE);
      }
 else {
        ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource,BundleEntrySearchModeEnum.MATCH);
      }
    }
 else {
      if (theRevIncludedPids.contains(next.getId())) {
        ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource)resource,BundleEntrySearchModeEnum.INCLUDE.getCode());
      }
 else {
        ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource)resource,BundleEntrySearchModeEnum.MATCH.getCode());
      }
    }
    theResourceListToPopulate.set(index,resource);
  }
}