JetBrains/intellij-community · error · ConfigurationException

''{0}'' is invalid field name for delegation

Error message

''{0}'' is invalid field name for delegation

What it means

InheritanceToDelegationDialog.canRun throws ConfigurationException (JavaRefactoringBundle key replace.inheritance.with.delegation.invalid.field) when the field name entered in the Replace Inheritance with Delegation dialog is not a valid Java identifier (PsiNameHelper.isIdentifier fails). The delegation target must become a real field, so its name must be a legal identifier and not a keyword.

Source

Thrown at java/java-impl-refactorings/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java:102

  public @Nullable String getInnerClassName() {
    if (myInnerClassNameField != null) {
      return myInnerClassNameField.getEnteredName();
    }
    else {
      return null;
    }
  }

  public boolean isGenerateGetter() {
    return myCbGenerateGetter.isSelected();
  }

  @Override
  protected void canRun() throws ConfigurationException {
    final String fieldName = getFieldName();
    final PsiNameHelper helper = PsiNameHelper.getInstance(myProject);
    if (!helper.isIdentifier(fieldName)){
      throw new ConfigurationException(JavaRefactoringBundle.message("replace.inheritance.with.delegation.invalid.field", fieldName));
    }
    if (myInnerClassNameField != null) {
      final String className = myInnerClassNameField.getEnteredName();
      if (!helper.isIdentifier(className)) {
        throw new ConfigurationException(JavaRefactoringBundle.message("replace.inheritance.with.delegation.invalid.inner.class",
                                                                       fieldName));
      }
    }
  }

  public Collection<MemberInfo> getSelectedMemberInfos() {
    return myMemberSelectionPanel.getTable().getSelectedMemberInfos();
  }

  public PsiClass getSelectedTargetClass() {
    return (PsiClass)myClassCombo.getSelectedItem();
  }

View on GitHub (pinned to be881553f2)

Solutions

  1. Enter a valid Java identifier (letters, digits, '_', '$'; not starting with a digit; not a keyword), e.g. 'delegate'.
  2. Remove spaces, dashes, and punctuation.
  3. Also make sure the name does not clash with existing members of the class (good practice even though not checked here).

Example fix

# before:
Field name: my-delegate

# after:
Field name: myDelegate
Defensive patterns

Strategy: validation

Validate before calling

if (!PsiNameHelper.getInstance(project).isIdentifier(getFieldName())) {
  // highlight field-name control with 'not a valid Java identifier'
}

Try / catch

try { dialog.canRun(); } catch (ConfigurationException e) { /* correct the field name and retry */ }

Prevention

When it happens

Trigger: Typing a field name like 'my-field', '2ndTarget', 'class', or leaving it empty in the Replace Inheritance with Delegation dialog, then pressing OK.

Common situations: Users typing labels or descriptions instead of identifiers; names with spaces/dashes from copy-paste; keyword names; empty field after dialog opens without default.

Related errors


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