JetBrains/intellij-community · error · ConfigurationException

module.paths.validation.duplicate.source.root.in.same.module.error

module.paths.validation.duplicate.source.root.in.same.module.error

Error message

Source root ''{0}'' is duplicated in module ''{1}''.

What it means

Thrown by ModulesConfigurator during Project Structure apply-time validation when the same source root VirtualFile appears twice within a single module's content entries. Duplicate source roots make indexing and compilation ambiguous, so the configurator rejects the whole module model update.

Source

Thrown at java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java:290

    @NotNull Map<VirtualFile, VirtualFile> srcRootsToContentRootMap
  ) throws ConfigurationException {

    // TODO IDEA-376062 allow duplicates only for supported build systems
    boolean duplicatesAreAllowed = CodeInsightContexts.isSharedSourceSupportEnabled(myProject);
    if (duplicatesAreAllowed) {
      return;
    }

    final ModuleRootModel rootModel = moduleEditor.getRootModel();
    final ContentEntry[] contents = rootModel.getContentEntries();
    final String moduleName = moduleEditor.getName();

    // Check for duplicate source roots within the same module
    Set<VirtualFile> sourceRoots = new HashSet<>();
    for (ContentEntry content : contents) {
      for (VirtualFile root : content.getSourceFolderFiles()) {
        if (!sourceRoots.add(root)) {
          throw new ConfigurationException(
            JavaUiBundle.message("module.paths.validation.duplicate.source.root.in.same.module.error", root.getPresentableUrl(),
                                 moduleName));
        }
      }
    }

    // Check for duplicate content roots across modules and map source roots to content roots
    for (ContentEntry contentEntry : contents) {
      final VirtualFile contentRoot = contentEntry.getFile();
      if (contentRoot == null) {
        continue;
      }

      // Check for duplicate content roots
      final String previousName = contentRootToModuleNameMap.put(contentRoot, moduleName);
      if (previousName != null && !previousName.equals(moduleName)) {
        throw new ConfigurationException(
          JavaUiBundle.message("module.paths.validation.duplicate.content.error", contentRoot.getPresentableUrl(), previousName, moduleName)

View on GitHub (pinned to be881553f2)

Solutions

  1. In Project Structure > Modules, expand the content entries and unmark/remove the duplicated source root so each folder appears once
  2. Edit the .iml directly: find the repeated <sourceFolder url="..."> entries and delete the duplicates, then reload
  3. If two content entries overlap, remove one of the overlapping content entries entirely

Example fix

<!-- before: my-module.iml -->
<component name="NewModuleRootManager">
  <content url="file://$MODULE_DIR$/a">
    <sourceFolder url="file://$MODULE_DIR$/a/src" isTestSource="false"/>
  </content>
  <content url="file://$MODULE_DIR$/b">
    <sourceFolder url="file://$MODULE_DIR$/a/src" isTestSource="false"/> <!-- duplicate -->
  </content>
</component>

<!-- after -->
<component name="NewModuleRootManager">
  <content url="file://$MODULE_DIR$/a">
    <sourceFolder url="file://$MODULE_DIR$/a/src" isTestSource="false"/>
  </content>
  <content url="file://$MODULE_DIR$/b"/>
</component>
Defensive patterns

Strategy: validation

Validate before calling

Set<VirtualFile> seen = new HashSet<>();
for (ContentEntry c : rootModel.getContentEntries()) {
  for (VirtualFile root : c.getSourceFolderFiles()) {
    if (!seen.add(root)) {
      // remove the duplicate source folder via ContentEntry.removeSourceFolder before apply
    }
  }
}

Try / catch

try {
  modulesConfigurator.apply(); // or commit module editor
} catch (ConfigurationException e) {
  // parse module name / root from message, unmark the duplicate, then let user re-apply
}

Prevention

When it happens

Trigger: Calling the configurator's validation (moduleEditor.getRootModel() content entries) after the user added the same folder as a source root under two different content entries of one module — the Set<VirtualFile> add() returns false on the second occurrence.

Common situations: Marking 'src' as Sources under two content roots that overlap; editing a misconfigured .iml by hand that lists the same source URL twice; copy-pasting a content entry in the iml; module with both 'src' and 'src/main/java' where the parent got marked too (exact duplicate case).

Related errors


AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14). Data as JSON: /api/errors/b63b28a0f3054dd6. Report an issue: GitHub.