diff --git a/java/java-tests/testData/moduleRootManager/unloadedModules/util.iml b/java/java-tests/testData/moduleRootManager/unloadedModules/util.iml index fefaba3e3a7b..d58b6709c851 100644 --- a/java/java-tests/testData/moduleRootManager/unloadedModules/util.iml +++ b/java/java-tests/testData/moduleRootManager/unloadedModules/util.iml @@ -5,5 +5,14 @@ + + + + + + + + + diff --git a/platform/workspaceModel/ide/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleManagerComponentBridge.kt b/platform/workspaceModel/ide/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleManagerComponentBridge.kt index bd40e6b1d18b..2b2ce00d87e0 100644 --- a/platform/workspaceModel/ide/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleManagerComponentBridge.kt +++ b/platform/workspaceModel/ide/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleManagerComponentBridge.kt @@ -288,25 +288,27 @@ class ModuleManagerComponentBridge(private val project: Project) : ModuleManager } } is EntityChange.Added -> { - val moduleRootComponent = getModuleRootComponentByLibrary(change.entity) - val library = event.storageAfter.libraryMap.getDataByEntity(change.entity) - if (library == null && WorkspaceModelTopics.getInstance(project).modulesAreLoaded) { - moduleRootComponent.moduleLibraryTable.addLibrary(change.entity, null) - } - if (library != null) { - (library as LibraryBridgeImpl).entityStorage = entityStore - library.clearTargetBuilder() + val tableId = change.entity.tableId as LibraryTableId.ModuleLibraryTableId + val moduleEntity = entityStore.current.resolve(tableId.moduleId) + ?: error("Could not find module for module library: ${change.entity.persistentId()}") + if (moduleEntity.name !in unloadedModules) { + + val library = event.storageAfter.libraryMap.getDataByEntity(change.entity) + if (library == null && WorkspaceModelTopics.getInstance(project).modulesAreLoaded) { + val module = entityStore.current.moduleMap.getDataByEntity(moduleEntity) + ?: error("Could not find module bridge for module entity $moduleEntity") + val moduleRootComponent = ModuleRootComponentBridge.getInstance(module) + moduleRootComponent.moduleLibraryTable.addLibrary(change.entity, null) + } + if (library != null) { + (library as LibraryBridgeImpl).entityStorage = entityStore + library.clearTargetBuilder() + } } } } } - private fun getModuleRootComponentByLibrary(entity: LibraryEntity): ModuleRootComponentBridge { - val tableId = entity.tableId as LibraryTableId.ModuleLibraryTableId - val module = findModuleByName(tableId.moduleId.name) ?: error("Could not find module for module library: ${entity.persistentId()}") - return ModuleRootComponentBridge.getInstance(module) - } - private fun addModule(moduleEntity: ModuleEntity): ModuleBridge { val module = createModuleInstance(moduleEntity, entityStore, diff = null, isNew = false) runWriteAction {