{"record":{"id":"f3d80bdc50fe4243","repo":"JetBrains/intellij-community","slug":"implicitly-declared-class-may-have-no-name","errorCode":null,"errorMessage":"Implicitly declared class may have no name","messagePattern":"Implicitly declared class may have no name","errorType":"exception","errorClass":"IncorrectOperationException","httpStatus":null,"severity":"error","filePath":"java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImplicitClassImpl.java","lineNumber":255,"sourceCode":"\n  @Override\n  public boolean isInheritorDeep(@NotNull PsiClass baseClass, @Nullable PsiClass classToByPass) {\n    return InheritanceImplUtil.isInheritorDeep(this, baseClass, classToByPass);\n  }\n\n  @Override\n  public @Nullable PsiClass getContainingClass() {\n    return null;\n  }\n\n  @Override\n  public @NotNull Collection<HierarchicalMethodSignature> getVisibleSignatures() {\n    return PsiSuperMethodImplUtil.getVisibleSignatures(this);\n  }\n\n  @Override\n  public PsiElement setName(@NotNull String name) throws IncorrectOperationException {\n    throw new IncorrectOperationException(\"Implicitly declared class may have no name\");\n  }\n\n  @Override\n  public boolean isDeprecated() {\n    return false;\n  }\n\n  @Override\n  public @Nullable PsiDocComment getDocComment() {\n    return null;\n  }\n\n  @Override\n  public @Nullable PsiModifierList getModifierList() {\n    return null;\n  }\n\n  @Override","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImplicitClassImpl.java#L237-L273","documentation":"PsiImplicitClassImpl models a Java 'implicitly declared class' (JEP 445 / unnamed classes, Java 21 preview feature): a compilation unit whose members live in a class with no declaration and no name. Since such a class has no name identifier in source, setName throws IncorrectOperationException(\"Implicitly declared class may have no name\").","triggerScenarios":"Calling setName on the PsiClass returned by PsiJavaFile.getClasses() for a file that is an implicit (unnamed) class, e.g. from a rename refactoring or a plugin that walks all classes in a file and renames them.","commonSituations":"Projects using Java 21+ preview features (unnamed classes with main); rename refactorings or code generators that assume every PsiClass has a name; structural searches that try to normalize class names.","solutions":["Skip name-based operations when the class has no name: check psiClass.getNameIdentifier() == null or instanceof PsiImplicitClassImpl before setName.","Rename the containing file instead (an implicit class is named by its file in tooling contexts); use RenameFileProcessor for such elements.","If the user tried to rename the class in the editor, guide them to rename the file, since the class name is derived.","Update plugins that assume named classes to handle JEP 445 files when the language level is 21+ with preview enabled."],"exampleFix":"// before\nfor (PsiClass c : javaFile.getClasses()) c.setName(newName); // throws on implicit class\n\n// after\nfor (PsiClass c : javaFile.getClasses()) {\n  if (c.getNameIdentifier() == null) continue; // implicit class: rename the file instead\nc.setName(newName);\n}","handlingStrategy":"type-guard","validationCode":"if (psiClass.getNameIdentifier() == null) continue; // implicit class cannot be renamed","typeGuard":"static boolean isImplicitClass(PsiClass c) { return c instanceof PsiImplicitClassImpl; }","tryCatchPattern":"try { psiClass.setName(n); } catch (IncorrectOperationException e) { /* offer file rename instead */ }","preventionTips":["Treat nameless PsiClass as file-bound; rename the file.","Test plugins against Java 21 preview (unnamed class) sources.","Check getNameIdentifier() before every setName on classes."],"tags":["java","psi","jep-445","unnamed-class","rename"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}