Program: 112973
Project: 112973
Buggy source:
private <T>void populateResults(final List<CloseableIterator<T>> results,final DataAdapter<Object> adapter,final PrimaryIndex index,final Query query,final DedupeFilter filter,final QueryOptions queryOptions,final boolean isDelete,final DataStoreCallbackManager callbackCache){
  final TreeSet<EntryRow> set=getRowsForIndex(index.getId());
  final Iterator<EntryRow> rowIt=((query == null) || query.isSupported(index)) ? ((TreeSet<EntryRow>)set.clone()).iterator() : Collections.<EntryRow>emptyIterator();
  final List<QueryFilter> filters=(query == null) ? new ArrayList<QueryFilter>() : new ArrayList<QueryFilter>(query.createFilters(index.getIndexModel()));
  filters.add(new QueryFilter(){
    @Override public boolean accept(    final CommonIndexModel indexModel,    final IndexedPersistenceEncoding persistenceEncoding){
      if (adapter.getAdapterId().equals(persistenceEncoding.getAdapterId())) {
        return true;
      }
      return false;
    }
  }
);
  if (filter != null)   filters.add(filter);
  results.add(new CloseableIterator<T>(){
    EntryRow nextRow=null;
    EntryRow currentRow=null;
    IndexedPersistenceEncoding encoding=null;
    private boolean getNext(){
      while ((nextRow == null) && rowIt.hasNext()) {
        final EntryRow row=rowIt.next();
        final DataAdapter<?> adapter=adapterStore.getAdapter(new ByteArrayId(row.getTableRowId().getAdapterId()));
        encoding=DataStoreUtils.getEncoding(index.getIndexModel(),adapter,row);
        boolean ok=true;
        for (        final QueryFilter filter : filters) {
          if (!filter.accept(index.getIndexModel(),encoding)) {
            ok=false;
            break;
          }
        }
        ok&=isAuthorized(row,queryOptions.getAuthorizations());
        if (ok) {
          nextRow=row;
          break;
        }
      }
      return (nextRow != null);
    }
    @Override public boolean hasNext(){
      return getNext();
    }
    @Override public T next(){
      currentRow=nextRow;
      if (isDelete) {
        final DataAdapter<T> adapter=(DataAdapter<T>)adapterStore.getAdapter(encoding.getAdapterId());
        if (adapter instanceof WritableDataAdapter) {
          callbackCache.getDeleteCallback((WritableDataAdapter<T>)adapter,index).entryDeleted(currentRow.getInfo(),(T)currentRow.entry);
        }
      }
      ((ScanCallback<T>)queryOptions.getScanCallback()).entryScanned(currentRow.getInfo(),(T)currentRow.entry);
      nextRow=null;
      return (T)currentRow.entry;
    }
    @Override public void remove(){
      if (currentRow != null) {
        set.remove(currentRow);
      }
    }
    @Override public void close() throws IOException {
      final ScanCallback<?> callback=queryOptions.getScanCallback();
      if ((callback != null) && (callback instanceof Closeable)) {
        ((Closeable)callback).close();
      }
    }
  }
);
}

Fixed version (ground truth):
private <T>void populateResults(final List<CloseableIterator<T>> results,final DataAdapter<Object> adapter,final PrimaryIndex index,final Query query,final DedupeFilter filter,final QueryOptions queryOptions,final boolean isDelete,final DataStoreCallbackManager callbackCache){
  final TreeSet<EntryRow> set=getRowsForIndex(index.getId());
  final Iterator<EntryRow> rowIt=((TreeSet<EntryRow>)set.clone()).iterator();
  final List<QueryFilter> filters=(query == null) ? new ArrayList<QueryFilter>() : new ArrayList<QueryFilter>(query.createFilters(index.getIndexModel()));
  filters.add(new QueryFilter(){
    @Override public boolean accept(    final CommonIndexModel indexModel,    final IndexedPersistenceEncoding persistenceEncoding){
      if (adapter.getAdapterId().equals(persistenceEncoding.getAdapterId())) {
        return true;
      }
      return false;
    }
  }
);
  if (filter != null)   filters.add(filter);
  results.add(new CloseableIterator<T>(){
    EntryRow nextRow=null;
    EntryRow currentRow=null;
    IndexedPersistenceEncoding encoding=null;
    private boolean getNext(){
      while ((nextRow == null) && rowIt.hasNext()) {
        final EntryRow row=rowIt.next();
        final DataAdapter<?> adapter=adapterStore.getAdapter(new ByteArrayId(row.getTableRowId().getAdapterId()));
        encoding=DataStoreUtils.getEncoding(index.getIndexModel(),adapter,row);
        boolean ok=true;
        for (        final QueryFilter filter : filters) {
          if (!filter.accept(index.getIndexModel(),encoding)) {
            ok=false;
            break;
          }
        }
        ok&=isAuthorized(row,queryOptions.getAuthorizations());
        if (ok) {
          nextRow=row;
          break;
        }
      }
      return (nextRow != null);
    }
    @Override public boolean hasNext(){
      return getNext();
    }
    @Override public T next(){
      currentRow=nextRow;
      if (isDelete) {
        final DataAdapter<T> adapter=(DataAdapter<T>)adapterStore.getAdapter(encoding.getAdapterId());
        if (adapter instanceof WritableDataAdapter) {
          callbackCache.getDeleteCallback((WritableDataAdapter<T>)adapter,index).entryDeleted(currentRow.getInfo(),(T)currentRow.entry);
        }
      }
      ((ScanCallback<T>)queryOptions.getScanCallback()).entryScanned(currentRow.getInfo(),(T)currentRow.entry);
      nextRow=null;
      return (T)currentRow.entry;
    }
    @Override public void remove(){
      if (currentRow != null) {
        set.remove(currentRow);
      }
    }
    @Override public void close() throws IOException {
      final ScanCallback<?> callback=queryOptions.getScanCallback();
      if ((callback != null) && (callback instanceof Closeable)) {
        ((Closeable)callback).close();
      }
    }
  }
);
}