JetBrains/intellij-community · error · ConfigurationException
Extracted class should have unique name. Name ''{0}'' is alr
Error message
Extracted class should have unique name. Name ''{0}'' is already in use by one of the inner classes What it means
ExtractClassDialog.canRun throws ConfigurationException (JavaBundle key extracted.class.should.have.unique.name) when the requested extracted class name equals the simple name of one of the inner classes being extracted together with it. Both would land as sibling classes in the same scope, so the duplicate name is rejected before the refactoring runs.
Source
Thrown at java/java-impl-refactorings/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java:192
final List<PsiMethod> methods = getMethodsToExtract();
final List<PsiField> fields = getFieldsToExtract();
final List<PsiClass> innerClasses = getClassesToExtract();
if (methods.isEmpty() && fields.isEmpty() && innerClasses.isEmpty()) {
throw new ConfigurationException(LangBundle.message("dialog.message.nothing.found.to.extract"));
}
final String className = getClassName();
if (className.isEmpty() || !nameHelper.isIdentifier(className)) {
throw new ConfigurationException(JavaBundle.message("invalid.extracted.class.name", className));
}
/*final String packageName = getPackageName();
if (packageName.length() == 0 || !nameHelper.isQualifiedName(packageName)) {
throw new ConfigurationException("\'" + packageName + "\' is invalid extracted class package name");
}*/
for (PsiClass innerClass : innerClasses) {
if (className.equals(innerClass.getName())) {
throw new ConfigurationException(
JavaBundle.message("extracted.class.should.have.unique.name", className));
}
}
}
public @NotNull String getPackageName() {
return packageTextField.getText().trim();
}
public @NotNull String getClassName() {
return classNameField.getText().trim();
}
public List<PsiField> getFieldsToExtract() {
return getMembersToExtract(true, PsiField.class);
}
public <T> List<T> getMembersToExtract(final boolean checked, Class<T> memberClass) {View on GitHub (pinned to be881553f2)
Solutions
- Rename the new extracted class to something not used by any extracted inner class.
- Alternatively, deselect the inner class from the extraction list if it should keep its slot.
- Rename the inner class first (Refactor > Rename), then extract with your preferred name.
Example fix
# before: Class name: Helper (inner class 'Helper' also selected) # after: Class name: ExtractedHelper
Defensive patterns
Strategy: validation
Validate before calling
for (PsiClass inner : getClassesToExtract()) {
if (className.equals(inner.getName())) {
// duplicate name: block OK or auto-suggest a unique name
}
} Try / catch
try { dialog.canRun(); } catch (ConfigurationException e) { /* rename extracted class or deselect/rename the inner class */ } Prevention
- Uniqueness-check the entered name against selected inner classes live.
- Auto-suggest a suffixed unique name when a collision is detected.
When it happens
Trigger: In the Extract Class dialog, setting 'Class name' to the same string as an inner class selected for extraction (e.g. class name 'Helper' while an inner class 'Helper' is checked in the members list).
Common situations: Keeping the default/typed name while also moving the identically named inner class; renaming during iterative extraction and forgetting the inner class carries the old name; extracting from a class that already contains a helper with the planned target name.
Related errors
- Nothing found to extract
- ''{0}'' is invalid extracted class name
- Invalid package name: {0}
- ''{0}'' is invalid field name for delegation
- ''{0}'' is invalid parameter name
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/721e4ce1b1353cc6.
Report an issue: GitHub.