Program: 33929
Project: 33929
Buggy source:
public SegmentResponse querySegment(QueryWithFilters queryWithFilters,int amount,FieldDoc after,FacetRequest facetRequest,SortRequest sortRequest,QueryCacheKey queryCacheKey,FetchType resultFetchType,List<String> fieldsToReturn,List<String> fieldsToMask) throws Exception {
  QueryResultCache qrc=queryResultCache;
  boolean useCache=(qrc != null) && ((segmentQueryCacheMaxAmount <= 0) || (segmentQueryCacheMaxAmount >= amount)) && queryCacheKey != null;
  if (useCache) {
    SegmentResponse cacheSegmentResponse=qrc.getCacheSegmentResponse(queryCacheKey);
    if (cacheSegmentResponse != null) {
      return cacheSegmentResponse;
    }
  }
  Query q=queryWithFilters.getQuery();
  if (!queryWithFilters.getFilterQueries().isEmpty()) {
    BooleanQuery.Builder booleanQuery=new BooleanQuery.Builder();
    for (    Query filterQuery : queryWithFilters.getFilterQueries()) {
      booleanQuery.add(filterQuery,BooleanClause.Occur.MUST);
    }
    q=new QueryWrapperFilter(booleanQuery.build());
  }
  reopenIndexWritersIfNecessary();
  openReaderIfChanges();
  IndexSearcher indexSearcher=new IndexSearcher(directoryReader);
  int hasMoreAmount=amount + 1;
  TopDocsCollector<?> collector;
  List<SortField> sortFields=new ArrayList<>();
  boolean sorting=(sortRequest != null) && !sortRequest.getFieldSortList().isEmpty();
  if (sorting) {
    for (    FieldSort fs : sortRequest.getFieldSortList()) {
      boolean reverse=Direction.DESCENDING.equals(fs.getDirection());
      String sortField=fs.getSortField();
      Lumongo.SortAs.SortType sortType=indexConfig.getSortType(sortField);
      if (IndexConfig.isNumericOrDateSortType(sortType)) {
        SortField.Type type;
        if (IndexConfig.isNumericIntSortType(sortType)) {
          type=SortField.Type.INT;
        }
 else         if (IndexConfig.isNumericLongSortType(sortType)) {
          type=SortField.Type.LONG;
        }
 else         if (IndexConfig.isNumericFloatSortType(sortType)) {
          type=SortField.Type.FLOAT;
        }
 else         if (IndexConfig.isNumericDoubleSortType(sortType)) {
          type=SortField.Type.DOUBLE;
        }
 else         if (IndexConfig.isNumericDateSortType(sortType)) {
          type=SortField.Type.LONG;
        }
 else {
          throw new Exception("String_Node_Str" + sortType + "String_Node_Str"+ sortField+ "String_Node_Str");
        }
        sortFields.add(new SortedNumericSortField(sortField,type,reverse));
      }
 else {
        sortFields.add(new SortedSetSortField(sortField,reverse));
      }
    }
    Sort sort=new Sort();
    sort.setSort(sortFields.toArray(new SortField[sortFields.size()]));
    collector=TopFieldCollector.create(sort,hasMoreAmount,after,true,true,true);
  }
 else {
    collector=TopScoreDocCollector.create(hasMoreAmount,after);
  }
  SegmentResponse.Builder builder=SegmentResponse.newBuilder();
  if ((facetRequest != null) && !facetRequest.getCountRequestList().isEmpty()) {
    FacetsCollector facetsCollector=new FacetsCollector();
    indexSearcher.search(q,MultiCollector.wrap(collector,facetsCollector));
    for (    CountRequest countRequest : facetRequest.getCountRequestList()) {
      String label=countRequest.getFacetField().getLabel();
      String indexFieldName=facetsConfig.getDimConfig(label).indexFieldName;
      DefaultSortedSetDocValuesReaderState state=new DefaultSortedSetDocValuesReaderState(directoryReader,indexFieldName);
      Facets facets=new SortedSetDocValuesFacetCounts(state,facetsCollector);
      int numOfFacets;
      if (countRequest.getSegmentFacets() != 0) {
        if (countRequest.getSegmentFacets() < countRequest.getMaxFacets()) {
          throw new IllegalArgumentException("String_Node_Str");
        }
        numOfFacets=countRequest.getSegmentFacets() + 1;
      }
 else {
        numOfFacets=state.getSize();
      }
      FacetResult facetResult=facets.getTopChildren(numOfFacets,label);
      handleFacetResult(builder,facetResult,countRequest);
    }
  }
 else {
    indexSearcher.search(q,collector);
  }
  ScoreDoc[] results=collector.topDocs().scoreDocs;
  int totalHits=collector.getTotalHits();
  builder.setTotalHits(totalHits);
  boolean moreAvailable=(results.length == hasMoreAmount);
  int numResults=Math.min(results.length,amount);
  for (int i=0; i < numResults; i++) {
    ScoredResult.Builder srBuilder=handleDocResult(indexSearcher,sortRequest,sorting,results,i,resultFetchType,fieldsToReturn,fieldsToMask);
    builder.addScoredResult(srBuilder.build());
  }
  if (moreAvailable) {
    ScoredResult.Builder srBuilder=handleDocResult(indexSearcher,sortRequest,sorting,results,numResults,resultFetchType,fieldsToReturn,fieldsToMask);
    builder.setNext(srBuilder);
  }
  builder.setIndexName(indexName);
  builder.setSegmentNumber(segmentNumber);
  SegmentResponse segmentResponse=builder.build();
  if (useCache) {
    qrc.storeInCache(queryCacheKey,segmentResponse);
  }
  return segmentResponse;
}

Fixed version (ground truth):
public SegmentResponse querySegment(QueryWithFilters queryWithFilters,int amount,FieldDoc after,FacetRequest facetRequest,SortRequest sortRequest,QueryCacheKey queryCacheKey,FetchType resultFetchType,List<String> fieldsToReturn,List<String> fieldsToMask) throws Exception {
  QueryResultCache qrc=queryResultCache;
  boolean useCache=(qrc != null) && ((segmentQueryCacheMaxAmount <= 0) || (segmentQueryCacheMaxAmount >= amount)) && queryCacheKey != null;
  if (useCache) {
    SegmentResponse cacheSegmentResponse=qrc.getCacheSegmentResponse(queryCacheKey);
    if (cacheSegmentResponse != null) {
      return cacheSegmentResponse;
    }
  }
  Query q=queryWithFilters.getQuery();
  if (!queryWithFilters.getFilterQueries().isEmpty()) {
    BooleanQuery.Builder booleanQuery=new BooleanQuery.Builder();
    for (    Query filterQuery : queryWithFilters.getFilterQueries()) {
      booleanQuery.add(filterQuery,BooleanClause.Occur.MUST);
    }
    booleanQuery.add(q,BooleanClause.Occur.MUST);
    q=new QueryWrapperFilter(booleanQuery.build());
  }
  reopenIndexWritersIfNecessary();
  openReaderIfChanges();
  IndexSearcher indexSearcher=new IndexSearcher(directoryReader);
  int hasMoreAmount=amount + 1;
  TopDocsCollector<?> collector;
  List<SortField> sortFields=new ArrayList<>();
  boolean sorting=(sortRequest != null) && !sortRequest.getFieldSortList().isEmpty();
  if (sorting) {
    for (    FieldSort fs : sortRequest.getFieldSortList()) {
      boolean reverse=Direction.DESCENDING.equals(fs.getDirection());
      String sortField=fs.getSortField();
      Lumongo.SortAs.SortType sortType=indexConfig.getSortType(sortField);
      if (IndexConfig.isNumericOrDateSortType(sortType)) {
        SortField.Type type;
        if (IndexConfig.isNumericIntSortType(sortType)) {
          type=SortField.Type.INT;
        }
 else         if (IndexConfig.isNumericLongSortType(sortType)) {
          type=SortField.Type.LONG;
        }
 else         if (IndexConfig.isNumericFloatSortType(sortType)) {
          type=SortField.Type.FLOAT;
        }
 else         if (IndexConfig.isNumericDoubleSortType(sortType)) {
          type=SortField.Type.DOUBLE;
        }
 else         if (IndexConfig.isNumericDateSortType(sortType)) {
          type=SortField.Type.LONG;
        }
 else {
          throw new Exception("String_Node_Str" + sortType + "String_Node_Str"+ sortField+ "String_Node_Str");
        }
        sortFields.add(new SortedNumericSortField(sortField,type,reverse));
      }
 else {
        sortFields.add(new SortedSetSortField(sortField,reverse));
      }
    }
    Sort sort=new Sort();
    sort.setSort(sortFields.toArray(new SortField[sortFields.size()]));
    collector=TopFieldCollector.create(sort,hasMoreAmount,after,true,true,true);
  }
 else {
    collector=TopScoreDocCollector.create(hasMoreAmount,after);
  }
  SegmentResponse.Builder builder=SegmentResponse.newBuilder();
  if ((facetRequest != null) && !facetRequest.getCountRequestList().isEmpty()) {
    FacetsCollector facetsCollector=new FacetsCollector();
    indexSearcher.search(q,MultiCollector.wrap(collector,facetsCollector));
    for (    CountRequest countRequest : facetRequest.getCountRequestList()) {
      String label=countRequest.getFacetField().getLabel();
      String indexFieldName=facetsConfig.getDimConfig(label).indexFieldName;
      DefaultSortedSetDocValuesReaderState state=new DefaultSortedSetDocValuesReaderState(directoryReader,indexFieldName);
      Facets facets=new SortedSetDocValuesFacetCounts(state,facetsCollector);
      int numOfFacets;
      if (countRequest.getSegmentFacets() != 0) {
        if (countRequest.getSegmentFacets() < countRequest.getMaxFacets()) {
          throw new IllegalArgumentException("String_Node_Str");
        }
        numOfFacets=countRequest.getSegmentFacets() + 1;
      }
 else {
        numOfFacets=state.getSize();
      }
      FacetResult facetResult=facets.getTopChildren(numOfFacets,label);
      handleFacetResult(builder,facetResult,countRequest);
    }
  }
 else {
    indexSearcher.search(q,collector);
  }
  ScoreDoc[] results=collector.topDocs().scoreDocs;
  int totalHits=collector.getTotalHits();
  builder.setTotalHits(totalHits);
  boolean moreAvailable=(results.length == hasMoreAmount);
  int numResults=Math.min(results.length,amount);
  for (int i=0; i < numResults; i++) {
    ScoredResult.Builder srBuilder=handleDocResult(indexSearcher,sortRequest,sorting,results,i,resultFetchType,fieldsToReturn,fieldsToMask);
    builder.addScoredResult(srBuilder.build());
  }
  if (moreAvailable) {
    ScoredResult.Builder srBuilder=handleDocResult(indexSearcher,sortRequest,sorting,results,numResults,resultFetchType,fieldsToReturn,fieldsToMask);
    builder.setNext(srBuilder);
  }
  builder.setIndexName(indexName);
  builder.setSegmentNumber(segmentNumber);
  SegmentResponse segmentResponse=builder.build();
  if (useCache) {
    qrc.storeInCache(queryCacheKey,segmentResponse);
  }
  return segmentResponse;
}