Program: 171034
Project: 171034
Buggy source:
@Override @GraphTransaction public AtlasSearchResult searchWithParameters(SearchParameters searchParameters) throws AtlasBaseException {
  AtlasSearchResult ret=new AtlasSearchResult(searchParameters);
  final QueryParams params=validateSearchParams(searchParameters.getLimit(),searchParameters.getOffset());
  searchParameters.setLimit(params.limit());
  searchParameters.setOffset(params.offset());
  SearchContext context=new SearchContext(searchParameters,typeRegistry,graph,indexer.getVertexIndexKeys());
  String searchID=searchTracker.add(context);
  try {
    List<AtlasVertex> resultList=context.getSearchProcessor().execute();
    Set<String> resultAttributes=new HashSet<>();
    Set<String> entityAttributes=new HashSet<>();
    if (CollectionUtils.isNotEmpty(searchParameters.getAttributes())) {
      resultAttributes.addAll(searchParameters.getAttributes());
    }
    if (CollectionUtils.isNotEmpty(context.getEntityAttributes())) {
      resultAttributes.addAll(context.getEntityAttributes());
    }
    AtlasEntityType entityType=context.getEntityType();
    if (entityType != null) {
      for (      String resultAttribute : resultAttributes) {
        AtlasAttribute attribute=entityType.getAttribute(resultAttribute);
        if (attribute != null) {
          AtlasType attributeType=attribute.getAttributeType();
          if (attributeType instanceof AtlasArrayType) {
            attributeType=((AtlasArrayType)attributeType).getElementType();
          }
          if (attributeType instanceof AtlasEntityType || attributeType instanceof AtlasObjectIdType) {
            entityAttributes.add(resultAttribute);
          }
        }
      }
    }
    for (    AtlasVertex atlasVertex : resultList) {
      AtlasEntityHeader entity=entityRetriever.toAtlasEntityHeader(atlasVertex,resultAttributes);
      if (searchParameters.getIncludeClassificationAttributes()) {
        entity.setClassifications(entityRetriever.getClassifications(atlasVertex));
      }
      ret.addEntity(entity);
      for (      String entityAttribute : entityAttributes) {
        Object attrValue=entity.getAttribute(entityAttribute);
        if (attrValue instanceof AtlasObjectId) {
          AtlasObjectId objId=(AtlasObjectId)attrValue;
          if (ret.getReferredEntities() == null) {
            ret.setReferredEntities(new HashMap<String,AtlasEntityHeader>());
          }
          if (!ret.getReferredEntities().containsKey(objId.getGuid())) {
            ret.getReferredEntities().put(objId.getGuid(),entityRetriever.toAtlasEntityHeader(objId.getGuid()));
          }
        }
 else         if (attrValue instanceof Collection) {
          Collection objIds=(Collection)attrValue;
          for (          Object obj : objIds) {
            if (obj instanceof AtlasObjectId) {
              AtlasObjectId objId=(AtlasObjectId)obj;
              if (ret.getReferredEntities() == null) {
                ret.setReferredEntities(new HashMap<String,AtlasEntityHeader>());
              }
              if (!ret.getReferredEntities().containsKey(objId.getGuid())) {
                ret.getReferredEntities().put(objId.getGuid(),entityRetriever.toAtlasEntityHeader(objId.getGuid()));
              }
            }
          }
        }
      }
    }
  }
  finally {
    searchTracker.remove(searchID);
  }
  return ret;
}

Fixed version (ground truth):
@Override @GraphTransaction public AtlasSearchResult searchWithParameters(SearchParameters searchParameters) throws AtlasBaseException {
  AtlasSearchResult ret=new AtlasSearchResult(searchParameters);
  final QueryParams params=QueryParams.getNormalizedParams(searchParameters.getLimit(),searchParameters.getOffset());
  searchParameters.setLimit(params.limit());
  searchParameters.setOffset(params.offset());
  SearchContext context=new SearchContext(searchParameters,typeRegistry,graph,indexer.getVertexIndexKeys());
  String searchID=searchTracker.add(context);
  try {
    List<AtlasVertex> resultList=context.getSearchProcessor().execute();
    Set<String> resultAttributes=new HashSet<>();
    Set<String> entityAttributes=new HashSet<>();
    if (CollectionUtils.isNotEmpty(searchParameters.getAttributes())) {
      resultAttributes.addAll(searchParameters.getAttributes());
    }
    if (CollectionUtils.isNotEmpty(context.getEntityAttributes())) {
      resultAttributes.addAll(context.getEntityAttributes());
    }
    AtlasEntityType entityType=context.getEntityType();
    if (entityType != null) {
      for (      String resultAttribute : resultAttributes) {
        AtlasAttribute attribute=entityType.getAttribute(resultAttribute);
        if (attribute != null) {
          AtlasType attributeType=attribute.getAttributeType();
          if (attributeType instanceof AtlasArrayType) {
            attributeType=((AtlasArrayType)attributeType).getElementType();
          }
          if (attributeType instanceof AtlasEntityType || attributeType instanceof AtlasObjectIdType) {
            entityAttributes.add(resultAttribute);
          }
        }
      }
    }
    for (    AtlasVertex atlasVertex : resultList) {
      AtlasEntityHeader entity=entityRetriever.toAtlasEntityHeader(atlasVertex,resultAttributes);
      if (searchParameters.getIncludeClassificationAttributes()) {
        entity.setClassifications(entityRetriever.getClassifications(atlasVertex));
      }
      ret.addEntity(entity);
      for (      String entityAttribute : entityAttributes) {
        Object attrValue=entity.getAttribute(entityAttribute);
        if (attrValue instanceof AtlasObjectId) {
          AtlasObjectId objId=(AtlasObjectId)attrValue;
          if (ret.getReferredEntities() == null) {
            ret.setReferredEntities(new HashMap<String,AtlasEntityHeader>());
          }
          if (!ret.getReferredEntities().containsKey(objId.getGuid())) {
            ret.getReferredEntities().put(objId.getGuid(),entityRetriever.toAtlasEntityHeader(objId.getGuid()));
          }
        }
 else         if (attrValue instanceof Collection) {
          Collection objIds=(Collection)attrValue;
          for (          Object obj : objIds) {
            if (obj instanceof AtlasObjectId) {
              AtlasObjectId objId=(AtlasObjectId)obj;
              if (ret.getReferredEntities() == null) {
                ret.setReferredEntities(new HashMap<String,AtlasEntityHeader>());
              }
              if (!ret.getReferredEntities().containsKey(objId.getGuid())) {
                ret.getReferredEntities().put(objId.getGuid(),entityRetriever.toAtlasEntityHeader(objId.getGuid()));
              }
            }
          }
        }
      }
    }
  }
  finally {
    searchTracker.remove(searchID);
  }
  return ret;
}