{"record":{"id":"721e4ce1b1353cc6","repo":"JetBrains/intellij-community","slug":"extracted-class-should-have-unique-name-name-0","errorCode":null,"errorMessage":"Extracted class should have unique name. Name ''{0}'' is already in use by one of the inner classes","messagePattern":"Extracted class should have unique name\\. Name ''(.+?)'' is already in use by one of the inner classes","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"java/java-impl-refactorings/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java","lineNumber":192,"sourceCode":"    final List<PsiMethod> methods = getMethodsToExtract();\n    final List<PsiField> fields = getFieldsToExtract();\n    final List<PsiClass> innerClasses = getClassesToExtract();\n    if (methods.isEmpty() && fields.isEmpty() && innerClasses.isEmpty()) {\n      throw new ConfigurationException(LangBundle.message(\"dialog.message.nothing.found.to.extract\"));\n    }\n\n    final String className = getClassName();\n    if (className.isEmpty() || !nameHelper.isIdentifier(className)) {\n      throw new ConfigurationException(JavaBundle.message(\"invalid.extracted.class.name\", className));\n    }\n\n    /*final String packageName = getPackageName();\n    if (packageName.length() == 0 || !nameHelper.isQualifiedName(packageName)) {\n      throw new ConfigurationException(\"\\'\" + packageName + \"\\' is invalid extracted class package name\");\n    }*/\n    for (PsiClass innerClass : innerClasses) {\n      if (className.equals(innerClass.getName())) {\n        throw new ConfigurationException(\n          JavaBundle.message(\"extracted.class.should.have.unique.name\", className));\n      }\n    }\n  }\n\n  public @NotNull String getPackageName() {\n    return packageTextField.getText().trim();\n  }\n\n  public @NotNull String getClassName() {\n    return classNameField.getText().trim();\n  }\n\n  public List<PsiField> getFieldsToExtract() {\n    return getMembersToExtract(true, PsiField.class);\n  }\n\n  public <T> List<T> getMembersToExtract(final boolean checked, Class<T> memberClass) {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl-refactorings/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java#L174-L210","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before:\nClass name: Helper   (inner class 'Helper' also selected)\n\n# after:\nClass name: ExtractedHelper","handlingStrategy":"validation","validationCode":"for (PsiClass inner : getClassesToExtract()) {\n  if (className.equals(inner.getName())) {\n    // duplicate name: block OK or auto-suggest a unique name\n  }\n}","typeGuard":null,"tryCatchPattern":"try { dialog.canRun(); } catch (ConfigurationException e) { /* rename extracted class or deselect/rename the inner class */ }","preventionTips":["Uniqueness-check the entered name against selected inner classes live.","Auto-suggest a suffixed unique name when a collision is detected."],"tags":["java","intellij","refactoring","extract-class","name-collision","validation","user-input"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}