Program: 5228
Project: 5228
Buggy source:
private SearchResults searchByCustomIndex(String namespaceId,Set<EntityTypeSimpleName> types,SortInfo sortInfo,int offset,int limit,int numCursors,@Nullable String cursor,boolean showHidden,Set<EntityScope> entityScope){
  List<MetadataEntry> returnedResults=new LinkedList<>();
  List<MetadataEntry> allResults=new LinkedList<>();
  String indexColumn=getIndexColumn(sortInfo.getSortBy(),sortInfo.getSortOrder());
  int fetchSize=offset + ((numCursors + 1) * limit);
  List<String> cursors=new ArrayList<>(numCursors);
  for (  String searchTerm : getSearchTerms(namespaceId,"String_Node_Str",entityScope)) {
    byte[] startKey=Bytes.toBytes(searchTerm.substring(0,searchTerm.lastIndexOf("String_Node_Str")));
    byte[] stopKey=Bytes.stopKeyForPrefix(startKey);
    if (!Strings.isNullOrEmpty(cursor)) {
      String namespaceInStartKey=searchTerm.substring(0,searchTerm.indexOf(KEYVALUE_SEPARATOR));
      startKey=Bytes.toBytes(namespaceInStartKey + KEYVALUE_SEPARATOR + cursor);
    }
    int mod=(limit == 1) ? 0 : 1;
    try (Scanner scanner=indexedTable.scanByIndex(Bytes.toBytes(indexColumn),startKey,stopKey)){
      Row next;
      while ((next=scanner.next()) != null) {
        Optional<MetadataEntry> metadataEntry=parseRow(next,indexColumn,types,showHidden);
        if (!metadataEntry.isPresent()) {
          continue;
        }
        allResults.add(metadataEntry.get());
        if (allResults.size() <= offset || allResults.size() > fetchSize) {
          continue;
        }
        if (returnedResults.size() < limit) {
          returnedResults.add(metadataEntry.get());
        }
 else {
          if ((allResults.size() - offset) % limit == mod) {
            String cursorWithNamespace=Bytes.toString(next.get(indexColumn));
            cursors.add(cursorWithNamespace.substring(cursorWithNamespace.indexOf(KEYVALUE_SEPARATOR) + 1));
          }
        }
      }
    }
   }
  return new SearchResults(returnedResults,cursors,allResults);
}

Fixed version (ground truth):
private SearchResults searchByCustomIndex(String namespaceId,Set<EntityTypeSimpleName> types,SortInfo sortInfo,int offset,int limit,int numCursors,@Nullable String cursor,boolean showHidden,Set<EntityScope> entityScope){
  List<MetadataEntry> returnedResults=new LinkedList<>();
  List<MetadataEntry> allResults=new LinkedList<>();
  String indexColumn=getIndexColumn(sortInfo.getSortBy(),sortInfo.getSortOrder());
  int fetchSize=(int)Math.min(offset + ((numCursors + 1) * (long)limit),Integer.MAX_VALUE);
  List<String> cursors=new ArrayList<>(numCursors);
  for (  String searchTerm : getSearchTerms(namespaceId,"String_Node_Str",entityScope)) {
    byte[] startKey=Bytes.toBytes(searchTerm.substring(0,searchTerm.lastIndexOf("String_Node_Str")));
    byte[] stopKey=Bytes.stopKeyForPrefix(startKey);
    if (!Strings.isNullOrEmpty(cursor)) {
      String namespaceInStartKey=searchTerm.substring(0,searchTerm.indexOf(KEYVALUE_SEPARATOR));
      startKey=Bytes.toBytes(namespaceInStartKey + KEYVALUE_SEPARATOR + cursor);
    }
    int mod=(limit == 1) ? 0 : 1;
    try (Scanner scanner=indexedTable.scanByIndex(Bytes.toBytes(indexColumn),startKey,stopKey)){
      Row next;
      while ((next=scanner.next()) != null && allResults.size() < fetchSize) {
        Optional<MetadataEntry> metadataEntry=parseRow(next,indexColumn,types,showHidden);
        if (!metadataEntry.isPresent()) {
          continue;
        }
        allResults.add(metadataEntry.get());
        if (allResults.size() <= offset) {
          continue;
        }
        if (returnedResults.size() < limit) {
          returnedResults.add(metadataEntry.get());
        }
 else {
          if ((allResults.size() - offset) % limit == mod) {
            String cursorWithNamespace=Bytes.toString(next.get(indexColumn));
            cursors.add(cursorWithNamespace.substring(cursorWithNamespace.indexOf(KEYVALUE_SEPARATOR) + 1));
          }
        }
      }
    }
   }
  return new SearchResults(returnedResults,cursors,allResults);
}