JetBrains/intellij-community · error · ConfigurationException
error.module.already.exists
Error message
error.module.already.exists
What it means
Thrown by RenameModuleAndDirectoryHandler.checkRenameModule (RenameModuleAndDirectoryHandler.java:144) when renaming a module (Rename on an IDEA module node) and ModuleManager's ModifiableModuleModel.renameModule throws ModuleWithNameAlreadyExists — another module in the project already carries the target name. Module names must be unique project-wide because they key run configurations, facets, and inter-module dependencies.
Source
Thrown at java/java-impl-refactorings/src/com/intellij/refactoring/rename/RenameModuleAndDirectoryHandler.java:144
}
@Override
protected @NotNull String getCommandName() {
return JavaRefactoringBundle.message("rename.module.directory.command", newName);
}
};
}
};
}
}
private static void checkRenameModule(@NotNull Module module, @NotNull String newName) throws ConfigurationException {
final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(module.getProject()).getModifiableModel();
try {
modifiableModel.renameModule(module, newName);
}
catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) {
throw new ConfigurationException(IdeBundle.message("error.module.already.exists", newName));
}
}
private static void renameModule(@NotNull Module module, @NotNull String newName) {
if (module.isDisposed()) {
// happens if module gets removed while Usages Preview is shown
}
else {
try {
final ModifiableModuleModel model = ModuleManager.getInstance(module.getProject()).getModifiableModel();
model.renameModule(module, newName);
model.commit();
}
catch (ModuleWithNameAlreadyExists ignored) {
// happens if another module gets renamed while Usages Preview is shown
}
}
}View on GitHub (pinned to be881553f2)
Solutions
- Choose a module name not used by any other module in the project (check Project Structure | Modules list first).
- Rename or remove the conflicting module before retrying.
- On case-only renames, rename to a temporary name first, then to the final case, to avoid collision with the old registration.
Example fix
// before // project has modules: [app, app2] // rename 'app' -> 'app2' -> ModuleWithNameAlreadyExists -> ConfigurationException // after // rename 'app' -> 'appLegacy' (unused) -> succeeds
Defensive patterns
Strategy: validation
Validate before calling
boolean nameTaken = ModuleManager.getInstance(project).findModuleByName(newName) != null;
if (nameTaken) {
// pick another module name before triggering Rename on the module node
} Try / catch
catch (ModuleWithNameAlreadyExists e) when scripting ModifiableModuleModel.renameModule directly {
// report the collision and do NOT commit the modifiable model
} Prevention
- Check ModuleManager.findModuleByName(newName) before any programmatic module rename.
- For case-only renames on macOS/Windows, rename via a temporary intermediate name.
When it happens
Trigger: Rename (Shift+F6) an IntelliJ module to a name that matches any existing module in the same project. The handler does a dry-run rename on a throwaway ModifiableModel purely to detect the collision; the model is deliberately not committed on failure.
Common situations: Renaming a forked/duplicated module (e.g. 'app' -> 'app2' when 'app2' exists), unifying names after copying a module directory, or renaming to a name differing only by case on case-insensitive filesystems where the old module still registers.
Related errors
- Extracted class should have unique name. Name ''{0}'' is alr
- Inner class with name ''{0}'' already exists
- dialog.message.valid.identifier
- Module '{0}' already exist in project. Please, specify anoth
- Enter module file location
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/e9a8f853924c68f0.
Report an issue: GitHub.