void () { // do not run read action inside myOpenCloseLock List<Module> compiledModules = ReadAction.nonBlocking(() -> { ModuleManager moduleManager = ModuleManager.getInstance(project); return ContainerUtil.mapNotNull(myDirtyScopeHolder.getCompilationAffectedModules(), moduleManager::findModuleByName); }).expireWith(this).executeSynchronously(); Module[] allModules = initialized ? null : allModules(); myCompilationCount.increment(); myOpenCloseLock.lock(); try { myActiveBuilds--; if (!initialized) { initialize(allModules, compiledModules); } else { myDirtyScopeHolder.compilerActivityFinished(compiledModules); } if (myActiveBuilds == 0 && project.isOpen()) { if (myReader != null) { LOG.warn("already opened – will be overridden"); myReader.close(false); } myReader = myReaderFactory.create(project); LOG.info("backward reference index reader " + (myReader == null ? "doesn't exist" : "is opened")); } } finally { myOpenCloseLock.unlock(); } }