Program: 52075
Project: 52075
Buggy source:
protected DiscoverResult retrieveResult(Context context,DiscoverQuery query,QueryResponse solrQueryResponse) throws SQLException {
  DiscoverResult result=new DiscoverResult();
  if (solrQueryResponse != null) {
    result.setSearchTime(solrQueryResponse.getQTime());
    result.setStart(query.getStart());
    result.setMaxResults(query.getMaxResults());
    result.setTotalSearchResults(solrQueryResponse.getResults().getNumFound());
    List<String> searchFields=query.getSearchFields();
    for (    SolrDocument doc : solrQueryResponse.getResults()) {
      DSpaceObject dso=findDSpaceObject(context,doc);
      if (dso != null) {
        result.addDSpaceObject(dso);
      }
 else {
        log.error(LogManager.getHeader(context,"String_Node_Str","String_Node_Str" + doc.getFirstValue("String_Node_Str")));
        continue;
      }
      DiscoverResult.SearchDocument resultDoc=new DiscoverResult.SearchDocument();
      for (      String field : searchFields) {
        List<String> valuesAsString=new ArrayList<String>();
        for (        Object o : doc.getFieldValues(field)) {
          valuesAsString.add(String.valueOf(o));
        }
        resultDoc.addSearchField(field,valuesAsString.toArray(new String[valuesAsString.size()]));
      }
      result.addSearchDocument(dso,resultDoc);
      if (solrQueryResponse.getHighlighting() != null) {
        Map<String,List<String>> highlightedFields=solrQueryResponse.getHighlighting().get(dso.getType() + "String_Node_Str" + dso.getID());
        if (MapUtils.isNotEmpty(highlightedFields)) {
          Map<String,List<String>> resultMap=new HashMap<String,List<String>>();
          for (          String key : highlightedFields.keySet()) {
            resultMap.put(key.substring(0,key.lastIndexOf("String_Node_Str")),highlightedFields.get(key));
          }
          result.addHighlightedResult(dso,new DiscoverResult.DSpaceObjectHighlightResult(dso,resultMap));
        }
      }
    }
    List<FacetField> facetFields=solrQueryResponse.getFacetFields();
    if (facetFields != null) {
      for (int i=0; i < facetFields.size(); i++) {
        FacetField facetField=facetFields.get(i);
        DiscoverFacetField facetFieldConfig=query.getFacetFields().get(i);
        List<FacetField.Count> facetValues=facetField.getValues();
        if (facetValues != null) {
          if (facetFieldConfig.getType().equals(DiscoveryConfigurationParameters.TYPE_DATE) && facetFieldConfig.getSortOrder().equals(DiscoveryConfigurationParameters.SORT.VALUE)) {
            Collections.reverse(facetValues);
          }
          for (          FacetField.Count facetValue : facetValues) {
            String displayedValue=transformDisplayedValue(context,facetField.getName(),facetValue.getName());
            String field=transformFacetField(facetFieldConfig,facetField.getName(),true);
            String authorityValue=transformAuthorityValue(context,facetField.getName(),facetValue.getName());
            String sortValue=transformSortValue(context,facetField.getName(),facetValue.getName());
            String filterValue=displayedValue;
            if (StringUtils.isNotBlank(authorityValue)) {
              filterValue=authorityValue;
            }
            result.addFacetResult(field,new DiscoverResult.FacetResult(filterValue,displayedValue,authorityValue,sortValue,facetValue.getCount()));
          }
        }
      }
    }
    if (solrQueryResponse.getFacetQuery() != null) {
      LinkedHashMap<String,Integer> sortedFacetQueries=new LinkedHashMap<String,Integer>(solrQueryResponse.getFacetQuery());
      for (      String facetQuery : sortedFacetQueries.keySet()) {
        String facetField=facetQuery.substring(0,facetQuery.indexOf("String_Node_Str"));
        String name=facetQuery.substring(facetQuery.indexOf('[') + 1);
        name=name.substring(0,name.lastIndexOf(']')).replaceAll("String_Node_Str","String_Node_Str");
        String filter=facetQuery.substring(facetQuery.indexOf('['));
        filter=filter.substring(0,filter.lastIndexOf(']') + 1);
        Integer count=sortedFacetQueries.get(facetQuery);
        if (0 < count) {
          result.addFacetResult(facetField,new DiscoverResult.FacetResult(filter,name,null,name,count));
        }
      }
    }
    if (solrQueryResponse.getSpellCheckResponse() != null) {
      String recommendedQuery=solrQueryResponse.getSpellCheckResponse().getCollatedResult();
      if (StringUtils.isNotBlank(recommendedQuery)) {
        result.setSpellCheckQuery(recommendedQuery);
      }
    }
  }
  return result;
}

Fixed version (ground truth):
protected DiscoverResult retrieveResult(Context context,DiscoverQuery query,QueryResponse solrQueryResponse) throws SQLException {
  DiscoverResult result=new DiscoverResult();
  if (solrQueryResponse != null) {
    result.setSearchTime(solrQueryResponse.getQTime());
    result.setStart(query.getStart());
    result.setMaxResults(query.getMaxResults());
    result.setTotalSearchResults(solrQueryResponse.getResults().getNumFound());
    List<String> searchFields=query.getSearchFields();
    for (    SolrDocument doc : solrQueryResponse.getResults()) {
      DSpaceObject dso=findDSpaceObject(context,doc);
      if (dso != null) {
        result.addDSpaceObject(dso);
      }
 else {
        log.error(LogManager.getHeader(context,"String_Node_Str","String_Node_Str" + doc.getFirstValue("String_Node_Str")));
        continue;
      }
      DiscoverResult.SearchDocument resultDoc=new DiscoverResult.SearchDocument();
      for (      String field : searchFields) {
        List<String> valuesAsString=new ArrayList<String>();
        for (        Object o : doc.getFieldValues(field)) {
          valuesAsString.add(String.valueOf(o));
        }
        resultDoc.addSearchField(field,valuesAsString.toArray(new String[valuesAsString.size()]));
      }
      result.addSearchDocument(dso,resultDoc);
      if (solrQueryResponse.getHighlighting() != null) {
        Map<String,List<String>> highlightedFields=solrQueryResponse.getHighlighting().get(dso.getType() + "String_Node_Str" + dso.getID());
        if (MapUtils.isNotEmpty(highlightedFields)) {
          Map<String,List<String>> resultMap=new HashMap<String,List<String>>();
          for (          String key : highlightedFields.keySet()) {
            resultMap.put(key.substring(0,key.lastIndexOf("String_Node_Str")),highlightedFields.get(key));
          }
          result.addHighlightedResult(dso,new DiscoverResult.DSpaceObjectHighlightResult(dso,resultMap));
        }
      }
    }
    List<FacetField> facetFields=solrQueryResponse.getFacetFields();
    if (facetFields != null) {
      for (int i=0; i < facetFields.size(); i++) {
        FacetField facetField=facetFields.get(i);
        DiscoverFacetField facetFieldConfig=query.getFacetFields().get(i);
        List<FacetField.Count> facetValues=facetField.getValues();
        if (facetValues != null) {
          if (facetFieldConfig.getType().equals(DiscoveryConfigurationParameters.TYPE_DATE) && facetFieldConfig.getSortOrder().equals(DiscoveryConfigurationParameters.SORT.VALUE)) {
            Collections.reverse(facetValues);
          }
          for (          FacetField.Count facetValue : facetValues) {
            String displayedValue=transformDisplayedValue(context,facetField.getName(),facetValue.getName());
            String field=transformFacetField(facetFieldConfig,facetField.getName(),true);
            String authorityValue=transformAuthorityValue(context,facetField.getName(),facetValue.getName());
            String sortValue=transformSortValue(context,facetField.getName(),facetValue.getName());
            String filterValue=displayedValue;
            if (StringUtils.isNotBlank(authorityValue)) {
              filterValue=authorityValue;
            }
            result.addFacetResult(field,new DiscoverResult.FacetResult(filterValue,displayedValue,authorityValue,sortValue,facetValue.getCount()));
          }
        }
      }
    }
    if (solrQueryResponse.getFacetQuery() != null) {
      LinkedHashMap<String,Integer> sortedFacetQueries=new LinkedHashMap<String,Integer>(solrQueryResponse.getFacetQuery());
      for (      String facetQuery : sortedFacetQueries.keySet()) {
        String facetField=facetQuery.substring(0,facetQuery.indexOf("String_Node_Str"));
        String name="String_Node_Str";
        String filter="String_Node_Str";
        if (facetQuery.indexOf('[') > -1 && facetQuery.lastIndexOf(']') > -1) {
          name=facetQuery.substring(facetQuery.indexOf('[') + 1);
          name=name.substring(0,name.lastIndexOf(']')).replaceAll("String_Node_Str","String_Node_Str");
          filter=facetQuery.substring(facetQuery.indexOf('['));
          filter=filter.substring(0,filter.lastIndexOf(']') + 1);
        }
        Integer count=sortedFacetQueries.get(facetQuery);
        if (0 < count) {
          result.addFacetResult(facetField,new DiscoverResult.FacetResult(filter,name,null,name,count));
        }
      }
    }
    if (solrQueryResponse.getSpellCheckResponse() != null) {
      String recommendedQuery=solrQueryResponse.getSpellCheckResponse().getCollatedResult();
      if (StringUtils.isNotBlank(recommendedQuery)) {
        result.setSpellCheckQuery(recommendedQuery);
      }
    }
  }
  return result;
}