private @Nullable <Key> IntSet getContainingIds(@NotNull StubIndexKey<Key, ?> indexKey,
                                                  @NotNull Key dataKey,
                                                  final @NotNull Project project,
                                                  @Nullable IdFilter idFilter,
                                                  final @Nullable GlobalSearchScope scope) {
    var trace = TRACE_OF_STUB_ENTRIES_LOOKUP.get();
    final FileBasedIndexEx fileBasedIndex = (FileBasedIndexEx)FileBasedIndex.getInstance();
    ID<Integer, SerializedStubTree> stubUpdatingIndexId = StubUpdatingIndex.INDEX_ID;
    final UpdatableIndex<Key, Void, FileContent, ?> index = getIndex(indexKey);   // wait for initialization to finish
    if (index == null || !fileBasedIndex.ensureUpToDate(stubUpdatingIndexId, project, scope, null)) return null;

    trace.indexValidationFinished();

    IdFilter finalIdFilter = idFilter != null
                             ? idFilter
                             : ((FileBasedIndexEx)FileBasedIndex.getInstance()).extractIdFilter(scope, project);

    UpdatableIndex<Integer, SerializedStubTree, FileContent, ?> stubUpdatingIndex = fileBasedIndex.getIndex(stubUpdatingIndexId);

    try {
      // workaround duplicates keys
      var action = new ValueContainer.ContainerAction<Void>() {
        IntSet result = null;

        @Override
        public boolean perform(int id, Void value) {
          if (finalIdFilter == null || finalIdFilter.containsFileId(id)) {
            if (result == null) {
              result = new IntLinkedOpenHashSet();
            }
            result.add(id);
          }
          return true;
        }
      };
      trace.totalKeysIndexed(MeasurableIndexStore.keysCountApproximatelyIfPossible(index));
      // disable up-to-date check to avoid locks on an attempt to acquire index write lock
      // while holding at the same time the readLock for this index
      FileBasedIndexEx.disableUpToDateCheckIn(() -> {
        Lock lock = stubUpdatingIndex.getLock().readLock();
        CancellationUtil.lockMaybeCancellable(lock);
        try {
          return index.getData(dataKey).forEach(action);
        }
        finally {
          lock.unlock();
        }
      });
      return action.result == null ? IntSets.EMPTY_SET : action.result;
    }
    catch (StorageException e) {
      trace.lookupFailed();
      forceRebuild(e);
    }
    catch (RuntimeException e) {
      trace.lookupFailed();
      final Throwable cause = FileBasedIndexEx.getCauseToRebuildIndex(e);
      if (cause != null) {
        forceRebuild(cause);
      }
      else {
        throw e;
      }
    }

    return null;
  }
private @Nullable <Key> IntSet getContainingIds(@NotNull StubIndexKey<Key, ?> indexKey,
                                                  @NotNull Key dataKey,
                                                  final @NotNull Project project,
                                                  @Nullable IdFilter idFilter,
                                                  final @Nullable GlobalSearchScope scope)