Program: 33927
Project: 33927
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 {
  try {
    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=booleanQuery.build();
    }
    reopenIndexWritersIfNecessary();
    openReaderIfChanges();
    IndexSearcher indexSearcher=new IndexSearcher(directoryReader);
    indexSearcher.setSimilarity(new PerFieldSimilarityWrapper(){
      @Override public Similarity get(      String name){
        LMAnalyzer analyzer=indexConfig.getAnalyzer(name);
        if (analyzer != null) {
          if (analyzer.equals(LMAnalyzer.LSH)) {
            return new LSHSimilarity();
          }
        }
        return new ClassicSimilarity();
      }
    }
);
    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;
        if (indexFieldName.equals(FacetsConfig.DEFAULT_INDEX_FIELD_NAME)) {
          throw new Exception(label + "String_Node_Str");
        }
        int numOfFacets=0;
        if (countRequest.getSegmentFacets() != 0) {
          if (countRequest.getSegmentFacets() < countRequest.getMaxFacets()) {
            throw new IllegalArgumentException("String_Node_Str");
          }
          numOfFacets=countRequest.getSegmentFacets() + 1;
        }
        FacetResult facetResult=null;
        try {
          DefaultSortedSetDocValuesReaderState state=new DefaultSortedSetDocValuesReaderState(directoryReader,indexFieldName);
          Facets facets=new SortedSetDocValuesFacetCounts(state,facetsCollector);
          if (countRequest.getSegmentFacets() == 0) {
            numOfFacets=state.getSize();
          }
          facetResult=facets.getTopChildren(numOfFacets,label);
        }
 catch (        IllegalArgumentException e) {
          if (e.getMessage().contains("String_Node_Str")) {
          }
 else {
            throw e;
          }
        }
        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;
  }
 catch (  IllegalStateException e) {
    Matcher m=sortedDocValuesMessage.matcher(e.getMessage());
    if (m.matches()) {
      String field=m.group(1);
      throw new Exception("String_Node_Str" + field + "String_Node_Str");
    }
    throw e;
  }
}

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 {
  try {
    reopenIndexWritersIfNecessary();
    openReaderIfChanges();
    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=booleanQuery.build();
    }
    IndexSearcher indexSearcher=new IndexSearcher(directoryReader);
    indexSearcher.setSimilarity(new PerFieldSimilarityWrapper(){
      @Override public Similarity get(      String name){
        LMAnalyzer analyzer=indexConfig.getAnalyzer(name);
        if (analyzer != null) {
          if (analyzer.equals(LMAnalyzer.LSH)) {
            return new LSHSimilarity();
          }
        }
        return new ClassicSimilarity();
      }
    }
);
    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;
        if (indexFieldName.equals(FacetsConfig.DEFAULT_INDEX_FIELD_NAME)) {
          throw new Exception(label + "String_Node_Str");
        }
        int numOfFacets=0;
        if (countRequest.getSegmentFacets() != 0) {
          if (countRequest.getSegmentFacets() < countRequest.getMaxFacets()) {
            throw new IllegalArgumentException("String_Node_Str");
          }
          numOfFacets=countRequest.getSegmentFacets() + 1;
        }
        FacetResult facetResult=null;
        try {
          DefaultSortedSetDocValuesReaderState state=new DefaultSortedSetDocValuesReaderState(directoryReader,indexFieldName);
          Facets facets=new SortedSetDocValuesFacetCounts(state,facetsCollector);
          if (countRequest.getSegmentFacets() == 0) {
            numOfFacets=state.getSize();
          }
          facetResult=facets.getTopChildren(numOfFacets,label);
        }
 catch (        IllegalArgumentException e) {
          if (e.getMessage().contains("String_Node_Str")) {
          }
 else {
            throw e;
          }
        }
        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;
  }
 catch (  IllegalStateException e) {
    Matcher m=sortedDocValuesMessage.matcher(e.getMessage());
    if (m.matches()) {
      String field=m.group(1);
      throw new Exception("String_Node_Str" + field + "String_Node_Str");
    }
    throw e;
  }
}