{"record":{"id":"b4f7fe36e1ed40d7","repo":"JetBrains/intellij-community","slug":"0-is-invalid-field-name-for-delegation","errorCode":null,"errorMessage":"''{0}'' is invalid field name for delegation","messagePattern":"''(.+?)'' is invalid field name for delegation","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"java/java-impl-refactorings/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java","lineNumber":102,"sourceCode":"  public @Nullable String getInnerClassName() {\n    if (myInnerClassNameField != null) {\n      return myInnerClassNameField.getEnteredName();\n    }\n    else {\n      return null;\n    }\n  }\n\n  public boolean isGenerateGetter() {\n    return myCbGenerateGetter.isSelected();\n  }\n\n  @Override\n  protected void canRun() throws ConfigurationException {\n    final String fieldName = getFieldName();\n    final PsiNameHelper helper = PsiNameHelper.getInstance(myProject);\n    if (!helper.isIdentifier(fieldName)){\n      throw new ConfigurationException(JavaRefactoringBundle.message(\"replace.inheritance.with.delegation.invalid.field\", fieldName));\n    }\n    if (myInnerClassNameField != null) {\n      final String className = myInnerClassNameField.getEnteredName();\n      if (!helper.isIdentifier(className)) {\n        throw new ConfigurationException(JavaRefactoringBundle.message(\"replace.inheritance.with.delegation.invalid.inner.class\",\n                                                                       fieldName));\n      }\n    }\n  }\n\n  public Collection<MemberInfo> getSelectedMemberInfos() {\n    return myMemberSelectionPanel.getTable().getSelectedMemberInfos();\n  }\n\n  public PsiClass getSelectedTargetClass() {\n    return (PsiClass)myClassCombo.getSelectedItem();\n  }\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl-refactorings/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java#L84-L120","documentation":"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.","triggerScenarios":"Typing a field name like 'my-field', '2ndTarget', 'class', or leaving it empty in the Replace Inheritance with Delegation dialog, then pressing OK.","commonSituations":"Users typing labels or descriptions instead of identifiers; names with spaces/dashes from copy-paste; keyword names; empty field after dialog opens without default.","solutions":["Enter a valid Java identifier (letters, digits, '_', '$'; not starting with a digit; not a keyword), e.g. 'delegate'.","Remove spaces, dashes, and punctuation.","Also make sure the name does not clash with existing members of the class (good practice even though not checked here)."],"exampleFix":"# before:\nField name: my-delegate\n\n# after:\nField name: myDelegate","handlingStrategy":"validation","validationCode":"if (!PsiNameHelper.getInstance(project).isIdentifier(getFieldName())) {\n  // highlight field-name control with 'not a valid Java identifier'\n}","typeGuard":null,"tryCatchPattern":"try { dialog.canRun(); } catch (ConfigurationException e) { /* correct the field name and retry */ }","preventionTips":["Validate the field with PsiNameHelper.isIdentifier as the user types.","Provide a default like 'delegate' so the field is never empty."],"tags":["java","intellij","refactoring","delegation","identifier","validation","user-input"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}