JetBrains/intellij-community · warning · ConfigurationException

''{0}'' is invalid parameter name

Error message

''{0}'' is invalid parameter name

What it means

Thrown by IntroduceParameterDialog.canRun() (java/java-impl-refactorings/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java:302) when the user-typed parameter name fails PsiNameHelper.isIdentifier(). It is a pre-flight validation of the Introduce Parameter refactoring: the dialog refuses to run until the name is a valid Java identifier for the project's language level. The ConfigurationException is caught by the refactoring dialog framework, which shows the message and keeps the dialog open.

Source

Thrown at java/java-impl-refactorings/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java:302

      myCbCollapseToLambda.isVisible() && myCbCollapseToLambda.isSelected(), selectedType, myPanel.getParametersToRemove());
    invokeRefactoring(processor);
  }


  private void updateFinalState() {
     if (myHasWriteAccess && myCbDeclareFinal != null) {
       myCbDeclareFinal.setEnabled(!myPanel.isReplaceAllOccurences());
       if (myPanel.isReplaceAllOccurences()) {
         myCbDeclareFinal.setSelected(false);
       }
     }
  }

  @Override
  protected void canRun() throws ConfigurationException {
    String name = getParameterName();
    if (!PsiNameHelper.getInstance(myProject).isIdentifier(name)) {
      throw new ConfigurationException(RefactoringBundle.message("refactoring.introduce.parameter.invalid.name", name));
    }
  }

  public void setReplaceAllOccurrences(IntroduceVariableBase.JavaReplaceChoice replaceChoice) {
    myReplaceChoice = replaceChoice;
    myPanel.setReplaceAllOccurrences(replaceChoice.isAll());
  }

  public void setGenerateDelegate(boolean delegate) {
    myPanel.setGenerateDelegate(delegate);
  }

  private class IntroduceParameterSettingsPanel extends IntroduceParameterSettingsUI {
    IntroduceParameterSettingsPanel(PsiLocalVariable onLocalVariable,
                                           PsiExpression onExpression,
                                           PsiMethod methodToReplaceIn, IntList parametersToRemove) {
      super(onLocalVariable, onExpression, methodToReplaceIn, parametersToRemove);
    }

View on GitHub (pinned to be881553f2)

Solutions

  1. Edit the Name field in the Introduce Parameter dialog to a valid Java identifier (letters, digits, '_', '$', not starting with a digit, not a keyword) and re-run.
  2. Check the module's language level if you believe the name is legal (e.g. contextual keywords) — PsiNameHelper validation is language-level sensitive.
  3. If driving the refactoring programmatically, validate the name with PsiNameHelper.getInstance(project).isIdentifier(name) before invoking the handler.

Example fix

// before
new IntroduceParameterHandler().invoke(project, editor, file, null);
// name left to dialog default that is not an identifier

// after
String name = suggestedName;
if (!PsiNameHelper.getInstance(project).isIdentifier(name)) {
  name = "param"; // fall back to a safe identifier
}
// then invoke the refactoring with the corrected name
Defensive patterns

Strategy: validation

Validate before calling

com.intellij.psi.PsiNameHelper helper = com.intellij.psi.PsiNameHelper.getInstance(project);
if (!helper.isIdentifier(parameterName)) {
  // fix or reject the name before invoking Introduce Parameter
  parameterName = "param";
}

Prevention

When it happens

Trigger: Calling the Introduce Parameter refactoring (Refactoring | Introduce Parameter) and confirming the dialog while the name field contains a non-identifier string: a keyword ('class', 'int'), a name starting with a digit ('1value'), empty text, or characters illegal at the current language level (e.g. 'my-param').

Common situations: Typos in the name field, names pasted with whitespace or dashes, using a Java keyword as a parameter name, or relying on identifiers with underscores/Restricted keywords that are invalid at the source level configured in the module.

Related errors


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