JetBrains/intellij-community · warning · ConfigurationException

Inner class with name ''{0}'' already exists

Error message

Inner class with name ''{0}'' already exists

What it means

Thrown by IntroduceParameterObjectDialog.canRun() (IntroduceParameterObjectDialog.java:483) when the chosen inner class name collides with an existing member: PsiClass.findInnerClassByName(innerClassName, false) returns non-null in the containing class. The refactoring would otherwise generate a duplicate class declaration, so the dialog blocks it. This is a name-collision check, not a syntax check.

Source

Thrown at java/java-impl-refactorings/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectDialog.java:483

    final ParameterInfoImpl[] infos = parameters.toArray(new ParameterInfoImpl[0]);
    return new JavaIntroduceParameterObjectClassDescriptor(className, packageName, moveDestination, useExistingClass, createInnerClass,
                                                           newVisibility, infos, mySourceMethod,
                                                           myGenerateAccessorsCheckBox.isSelected());
  }

  @Override
  protected void canRun() throws ConfigurationException {
    super.canRun();
    final Project project = mySourceMethod.getProject();
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
    if (myCreateInnerClassRadioButton.isSelected()) {
      final String innerClassName = getInnerClassName();
      if (!nameHelper.isIdentifier(innerClassName)) {
        throw new ConfigurationException(
          JavaRefactoringBundle.message("introduce.parameter.object.error.invalid.inner.class.name", innerClassName));
      }
      if (mySourceMethod.getContainingClass().findInnerClassByName(innerClassName, false) != null) {
        throw new ConfigurationException(
          JavaRefactoringBundle.message("introduce.parameter.object.error.inner.class.already.exist", innerClassName));
      }
    }
    else if (!useExistingClass()) {
      final String className = getClassName();
      if (className.isEmpty() || !nameHelper.isIdentifier(className)) {
        throw new ConfigurationException(
          JavaRefactoringBundle.message("introduce.parameter.object.error.invalid.parameter.class.name", className));
      }
      final String packageName = getPackageName();

      if (packageName.isEmpty() || !nameHelper.isQualifiedName(packageName)) {
        throw new ConfigurationException(
          JavaRefactoringBundle.message("introduce.parameter.object.error.invalid.parameter.class.package.name", packageName));
      }
    }
    else {
      final String className = getExistingClassName();

View on GitHub (pinned to be881553f2)

Solutions

  1. Pick a different inner class name in the dialog (e.g. suffix it: 'Params2', 'RequestWrapper').
  2. Or rename/delete the existing colliding inner class first via Safe Delete / Rename.
  3. Or switch the dialog to the 'Use existing class' option and select the class that already exists.

Example fix

// before
// containing class already declares:
// class Foo { static class FooParams {} void m(int a) {...} }
// dialog inner class name: FooParams  -> ConfigurationException

// after
// dialog inner class name: FooRequestParams  -> no collision, refactoring proceeds
Defensive patterns

Strategy: validation

Validate before calling

PsiClass container = mySourceMethod.getContainingClass();
String innerClassName = getInnerClassName();
if (container.findInnerClassByName(innerClassName, false) != null) {
  // suggest a non-colliding name before running the refactoring
  innerClassName = innerClassName + "Params"; // or open a chooser
}

Prevention

When it happens

Trigger: Introduce Parameter Object with 'Create inner class' selected and a name that already names an inner class (including non-executable/annotation inner classes) of the source method's containing class. For example the method lives in Foo and 'FooParams' already exists inside Foo.

Common situations: Running the refactoring twice and accepting the default suggested name a second time, or manually typing a name of a nested class you forgot about; also nested classes not visible in the Project view.

Related errors


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