{"record":{"id":"35baa795963a703c","repo":"JetBrains/intellij-community","slug":"module-paths-validation-source-root-belongs-to-ano","errorCode":"module.paths.validation.source.root.belongs.to.another.module.error","errorMessage":"Source root ''{0}''\ncannot be defined in module ''{1}'' because it belongs to content of nested module ''{2}''","messagePattern":"Source root ''(.+?)''\ncannot be defined in module ''(.+?)'' because it belongs to content of nested module ''(.+?)''","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java","lineNumber":359,"sourceCode":"    );\n  }\n\n  /**\n   * Validates that source roots belong to the same module as their corresponding content root.\n   */\n  private static void validateSourceRootsAcrossModules(@NotNull Map<VirtualFile, VirtualFile> srcRootsToContentRootMap,\n                                                       @NotNull Map<VirtualFile, String> contentRootToModuleNameMap) throws ConfigurationException {\n    for (Map.Entry<VirtualFile, VirtualFile> entry : srcRootsToContentRootMap.entrySet()) {\n      final VirtualFile srcRoot = entry.getKey();\n      final VirtualFile correspondingContent = entry.getValue();\n      final String expectedModuleName = contentRootToModuleNameMap.get(correspondingContent);\n\n      for (VirtualFile candidateContent = srcRoot;\n           candidateContent != null && !candidateContent.equals(correspondingContent);\n           candidateContent = candidateContent.getParent()) {\n        final String moduleName = contentRootToModuleNameMap.get(candidateContent);\n        if (moduleName != null && !moduleName.equals(expectedModuleName)) {\n          throw new ConfigurationException(\n            JavaUiBundle.message(\"module.paths.validation.source.root.belongs.to.another.module.error\", srcRoot.getPresentableUrl(), expectedModuleName, moduleName)\n          );\n        }\n      }\n    }\n  }\n\n  /**\n   * Validates that all module editors can be applied.\n   */\n  private void validateModuleEditors() throws ConfigurationException {\n    for (ModuleEditor moduleEditor : myModuleEditors.values()) {\n      moduleEditor.canApply();\n    }\n  }\n\n  /**\n   * Creates a mapping from modified SDKs to original SDKs.","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java#L341-L377","documentation":"Thrown by the Project Structure dialog when a source root configured in one module physically lives inside a content root owned by another, nested module. validateSourceRootsAcrossModules walks up from each source root to its declared content root and fails if any intermediate directory is registered as another module's content. IntelliJ rejects this because two modules would then claim the same files, breaking compilation and indexing.","triggerScenarios":"Calling apply/OK in Settings > Project Structure when module A declares a source root whose path is under a directory that is a content root of module B. Occurs after importing a project where nested modules overlap (e.g. a parent module whose content root contains a submodule's content root), or after manually editing .iml content/source entries so they overlap.","commonSituations":"Maven/Gradle imports producing overlapping module roots; monorepo layouts where an outer module was given a content root covering inner modules; duplicated content roots after moving directories without updating module configuration; hand-edited .iml files.","solutions":["In Project Structure > Modules, open the offending module and remove or re-path the source root so it is no longer inside another module's content root","Check the nested module (name in the error's third placeholder) and exclude the overlapping directory from its content entries","If the modules were imported, re-import the Maven/Gradle project so roots are regenerated from the build files","Inspect the two .iml files and fix the <content> / <sourceFolder> url attributes to not overlap"],"exampleFix":"<!-- before: module A .iml claims src that lives under module B's content root -->\n<content url=\"file://$MODULE_DIR$/subproject/src\" rootFolder=\"true\">\n<!-- after: remove the overlapping root from A; let B own it -->\n<content url=\"file://$MODULE_DIR$/subproject\" exported=\"\">\n  <excludeFolder url=\"file://$MODULE_DIR$/subproject/src\" />\n</content>","handlingStrategy":"validation","validationCode":"// Before apply(), verify no source root is nested in another module's content root\nMap<VirtualFile, String> contentToModule = collectContentRootToModuleName(modulesModel);\nfor (Module module : modulesModel.getModules()) {\n  for (ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) {\n    for (SourceFolder src : entry.getSourceFolders()) {\n      for (VirtualFile p = src.getFile(); p != null && !p.equals(entry.getFile()); p = p.getParent()) {\n        String owner = contentToModule.get(p);\n        if (owner != null && !owner.equals(module.getName())) {\n          // report: source root belongs to nested module 'owner'\n        }\n      }\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try { configurator.apply(); } catch (ConfigurationException e) { /* show e.getMessage() near module tree */ }","preventionTips":["Keep each module's content root disjoint from other modules' content roots","Prefer build-file-driven imports (Maven/Gradle) over hand-editing roots","After moving directories, re-run Project Structure validation before applying"],"tags":["intellij","project-structure","modules","validation","source-roots"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}