Program: 5548
Project: 5548
Buggy source:
private MetadataSearchResponse search(Set<MetadataScope> scopes,String namespaceId,String searchQuery,Set<MetadataSearchTargetType> types,SortInfo sortInfo,int offset,int limit,int numCursors,String cursor,boolean showHidden) throws BadRequestException {
  List<MetadataEntry> results=new ArrayList<>();
  List<String> cursors=new ArrayList<>();
  for (  MetadataScope scope : scopes) {
    SearchResults searchResults=getSearchResults(scope,namespaceId,searchQuery,types,sortInfo,offset,limit,numCursors,cursor,showHidden);
    results.addAll(searchResults.getResults());
    cursors.addAll(searchResults.getCursors());
  }
  Set<NamespacedEntityId> sortedEntities=getSortedEntities(results,sortInfo);
  int startIndex=0;
  int maxEndIndex;
  int total=sortedEntities.size();
  if (SortInfo.DEFAULT.equals(sortInfo)) {
    if (offset > sortedEntities.size()) {
      maxEndIndex=0;
    }
 else {
      startIndex=offset;
      maxEndIndex=offset + limit;
    }
  }
 else {
    maxEndIndex=limit;
    total+=offset;
  }
  sortedEntities=new LinkedHashSet<>(ImmutableList.copyOf(sortedEntities).subList(startIndex,Math.min(maxEndIndex,sortedEntities.size())));
  Map<NamespacedEntityId,Metadata> systemMetadata=fetchMetadata(sortedEntities,MetadataScope.SYSTEM);
  Map<NamespacedEntityId,Metadata> userMetadata=fetchMetadata(sortedEntities,MetadataScope.USER);
  return new MetadataSearchResponse(sortInfo.getSortBy() + "String_Node_Str" + sortInfo.getSortOrder(),offset,limit,numCursors,total,addMetadataToEntities(sortedEntities,systemMetadata,userMetadata),cursors,showHidden);
}

Fixed version (ground truth):
private MetadataSearchResponse search(Set<MetadataScope> scopes,String namespaceId,String searchQuery,Set<MetadataSearchTargetType> types,SortInfo sortInfo,int offset,int limit,int numCursors,String cursor,boolean showHidden) throws BadRequestException {
  List<MetadataEntry> results=new ArrayList<>();
  List<String> cursors=new ArrayList<>();
  for (  MetadataScope scope : scopes) {
    SearchResults searchResults=getSearchResults(scope,namespaceId,searchQuery,types,sortInfo,offset,limit,numCursors,cursor,showHidden);
    results.addAll(searchResults.getResults());
    cursors.addAll(searchResults.getCursors());
  }
  Set<NamespacedEntityId> sortedEntities=getSortedEntities(results,sortInfo);
  int startIndex=0;
  int maxEndIndex;
  int total=sortedEntities.size();
  if (SortInfo.DEFAULT.equals(sortInfo)) {
    if (offset > sortedEntities.size()) {
      maxEndIndex=0;
    }
 else {
      startIndex=offset;
      maxEndIndex=(int)Math.min(Integer.MAX_VALUE,(long)offset + limit);
    }
  }
 else {
    maxEndIndex=limit;
    total+=offset;
  }
  sortedEntities=new LinkedHashSet<>(ImmutableList.copyOf(sortedEntities).subList(startIndex,Math.min(maxEndIndex,sortedEntities.size())));
  Map<NamespacedEntityId,Metadata> systemMetadata=fetchMetadata(sortedEntities,MetadataScope.SYSTEM);
  Map<NamespacedEntityId,Metadata> userMetadata=fetchMetadata(sortedEntities,MetadataScope.USER);
  return new MetadataSearchResponse(sortInfo.getSortBy() + "String_Node_Str" + sortInfo.getSortOrder(),offset,limit,numCursors,total,addMetadataToEntities(sortedEntities,systemMetadata,userMetadata),cursors,showHidden);
}