{"record":{"id":"47c005abbfa2733d","repo":"JetBrains/intellij-community","slug":"cannot-create-0-incorrect-1-template","errorCode":null,"errorMessage":"Cannot create {0} - incorrect {1} template.","messagePattern":"Cannot create (.+?) - incorrect (.+?) template\\.","errorType":"exception","errorClass":"IncorrectOperationException","httpStatus":null,"severity":"error","filePath":"java/java-impl/src/com/intellij/psi/impl/file/JavaDirectoryServiceImpl.java","lineNumber":106,"sourceCode":"                              @NotNull String templateName,\n                              boolean askForUndefinedVariables) throws IncorrectOperationException {\n    return createClass(dir, name, templateName, askForUndefinedVariables, Collections.emptyMap());\n  }\n\n  @Override\n  public PsiClass createClass(@NotNull PsiDirectory dir,\n                              @NotNull String name,\n                              @NotNull String templateName,\n                              boolean askForUndefinedVariables, final @NotNull Map<String, String> additionalProperties) throws IncorrectOperationException {\n    return createClassFromTemplate(dir, name, templateName, askForUndefinedVariables, additionalProperties);\n  }\n\n  @Override\n  public @NotNull PsiClass createInterface(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {\n    String templateName = JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME;\n    PsiClass someClass = createClassFromTemplate(dir, name, templateName);\n    if (!someClass.isInterface()) {\n      throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, dir.getProject()));\n    }\n    return someClass;\n  }\n\n  @Override\n  public @NotNull PsiClass createEnum(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {\n    String templateName = JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME;\n    PsiClass someClass = createClassFromTemplate(dir, name, templateName);\n    if (!someClass.isEnum()) {\n      throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, dir.getProject()));\n    }\n    return someClass;\n  }\n\n  @Override\n  public @NotNull PsiClass createRecord(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {\n    String templateName = JavaTemplateUtil.INTERNAL_RECORD_TEMPLATE_NAME;\n    PsiClass someClass = createClassFromTemplate(dir, name, templateName);","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl/src/com/intellij/psi/impl/file/JavaDirectoryServiceImpl.java#L88-L124","documentation":"Thrown by JavaDirectoryServiceImpl.createInterface() when the internal file template used to create a new interface (JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME) yields a PsiClass that is not an interface. The check is someClass.isInterface() after instantiateClassFromTemplate; failure means the 'interface' keyword was removed from the customized template. It is an IncorrectOperationException aborting the create-from-template action.","triggerScenarios":"Calling JavaDirectoryService.createInterface(dir, name) or the New > Interface action when the internal interface template (file template used for internal creation) has been edited so it no longer declares an interface (e.g. 'interface ${NAME}' replaced with 'class ${NAME}').","commonSituations":"A user customized internal code templates via Settings > Editor > File and Code Templates and broke the interface template; a plugin or settings sync shipped a corrupted template; restoring defaults only for some templates after an IDE upgrade.","solutions":["Open Settings > Editor > File and Code Templates, find the internal interface template and restore it so it still contains 'interface ${NAME} { ... }'.","If unsure which template is broken, reset all file templates to defaults (the templates tab's reset action) and retry creating the interface.","Check whether a plugin injects or overrides code templates and disable it temporarily.","For plugin authors: ensure you pass JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME and do not customize it to a non-interface."],"exampleFix":"// template before (broken)\n#parse(\"File Header.java\")\nclass ${NAME} {\n}\n// template after (fixed)\n#parse(\"File Header.java\")\npublic interface ${NAME} {\n}","handlingStrategy":"validation","validationCode":"FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME);\nString text = template.getText();\nif (!text.contains(\"interface\")) {\n  // template broken; reset before calling createInterface\n}","typeGuard":null,"tryCatchPattern":"try { JavaDirectoryService.getInstance().createInterface(dir, name); } catch (IncorrectOperationException e) { /* report template name from message, reset template */ }","preventionTips":["Do not customize internal templates (INTERFACE/ENUM/RECORD/ANNOTATION) by removing their type keyword; keep 'interface ${NAME}'.","After changing file templates, immediately test New > Interface in a scratch project.","Reset templates to defaults before reporting platform bugs about class creation."],"tags":["java","file-template","create-class","intellij-platform"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}