JetBrains/intellij-community · warning · ConfigurationException

''{0}'' is invalid inner class name

Error message

''{0}'' is invalid inner class name

What it means

Thrown by IntroduceParameterObjectDialog.canRun() (IntroduceParameterObjectDialog.java:479) when the 'Create inner class' option is selected and the typed inner class name fails PsiNameHelper.isIdentifier(). The Introduce Parameter Object refactoring will generate a wrapper class, and the dialog pre-validates that the generated class name is a legal Java identifier. The framework catches the ConfigurationException and highlights the message without closing the dialog.

Source

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

        int oldParameterIndex = parameterList.getParameterIndex((PsiParameter)data.variable);
        parameters.add(ParameterInfoImpl.create(oldParameterIndex).withName(data.name).withType(data.type));
      }
    }
    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));

View on GitHub (pinned to be881553f2)

Solutions

  1. Correct the inner class name field to a valid Java identifier and confirm the dialog again.
  2. If the name looks legal, verify the module language level — PsiNameHelper rejects identifiers illegal at that level.
  3. In plugins/tests driving this refactoring programmatically, pre-check with PsiNameHelper.getInstance(project).isIdentifier(innerClassName).

Example fix

// before
String innerClassName = "request-params"; // user typed dashed name

// after
String innerClassName = "requestParams";
assert PsiNameHelper.getInstance(project).isIdentifier(innerClassName);
Defensive patterns

Strategy: validation

Validate before calling

PsiNameHelper helper = PsiNameHelper.getInstance(project);
String innerClassName = myInnerClassNameTextField.getText().trim();
if (!helper.isIdentifier(innerClassName)) {
  Messages.showErrorDialog(project, "Invalid inner class name: " + innerClassName, "Introduce Parameter Object");
  return; // do not open/confirm the dialog
}

Prevention

When it happens

Trigger: Refactoring | Introduce Parameter Object with the 'Create inner class' radio selected, and the inner class name field containing a keyword, a digit-leading name, an empty string, or other non-identifier text when OK is pressed.

Common situations: Typing a desired wrapper name like 'Request-Params' or '2Params', leaving the field blank after clearing a suggested name, or using a reserved word such as 'Record' at an older language level.

Related errors


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