NotNullLazyValue<InvertedNameIndex> (@NotNull ExecutorService pool, @NotNull PersistentFSRecordsStorage recordsStorage) { Future<InvertedNameIndex> fillUpInvertedNameIndexTask = pool.submit(() -> { InvertedNameIndex invertedNameIndex = new InvertedNameIndex(); //fill up nameId->fileId index: int maxAllocatedID = recordsStorage.maxAllocatedID(); for (int fileId = FSRecords.ROOT_FILE_ID; fileId <= maxAllocatedID; fileId++) { int flags = recordsStorage.getFlags(fileId); int nameId = recordsStorage.getNameId(fileId); if (!hasDeletedFlag(flags) && nameId != NULL_NAME_ID) { invertedNameIndex.updateDataInner(fileId, nameId); } } LOG.info("VFS scanned: file-by-name index was populated"); return invertedNameIndex; }); //We don't need volatile/atomicLazy, since computation is idempotent: same instance returned always. // So _there could be_ a data race, but it is a benign race. return NotNullLazyValue.lazy(() -> { try { return fillUpInvertedNameIndexTask.get(); } catch (Throwable e) { throw new IllegalStateException("Lazy invertedNameIndex computation is failed", e); } }); }