{"record":{"id":"a0b8664cab281e3e","repo":"JetBrains/intellij-community","slug":"annotations-only-supported-at-language-level-1-5-a","errorCode":null,"errorMessage":"Annotations only supported at language level 1.5 and higher","messagePattern":"Annotations only supported at language level 1\\.5 and higher","errorType":"exception","errorClass":"IncorrectOperationException","httpStatus":null,"severity":"error","filePath":"java/java-impl/src/com/intellij/ide/fileTemplates/JavaCreateFromTemplateHandler.java","lineNumber":76,"sourceCode":"    }\n    final PsiClass[] classes = psiJavaFile.getClasses();\n    if (classes.length == 0) {\n      throw new IncorrectOperationException(\"This template did not produce a Java class or an interface\\n\"+psiFile.getText());\n    }\n    PsiClass createdClass = classes[0];\n    String className;\n    if (optionalClassName != null && createdClass instanceof PsiImplicitClass) {\n      className = optionalClassName;\n    }\n    else {\n      className = createdClass.getName();\n    }\n    JavaDirectoryServiceImpl.checkCreateClassOrInterface(directory, className);\n\n    final LanguageLevel ll = JavaDirectoryService.getInstance().getLanguageLevel(directory);\n    if (ll.compareTo(LanguageLevel.JDK_1_5) < 0) {\n      if (createdClass.isAnnotationType()) {\n        throw new IncorrectOperationException(\"Annotations only supported at language level 1.5 and higher\");\n      }\n\n      if (createdClass.isEnum()) {\n        throw new IncorrectOperationException(\"Enums only supported at language level 1.5 and higher\");\n      }\n    }\n\n    psiJavaFile = (PsiJavaFile)psiJavaFile.setName(className + \".\" + extension);\n    PsiElement addedElement = directory.add(psiJavaFile);\n    if (addedElement instanceof PsiJavaFile) {\n      psiJavaFile = (PsiJavaFile)addedElement;\n      if(reformat){\n        CodeStyleManager.getInstance(project).scheduleReformatWhenSettingsComputed(psiJavaFile);\n      }\n\n      return psiJavaFile.getClasses()[0];\n    }\n    else {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl/src/com/intellij/ide/fileTemplates/JavaCreateFromTemplateHandler.java#L58-L94","documentation":"After creating the class from template, the handler checks the effective language level of the target directory (JavaDirectoryService.getLanguageLevel); if it is below JDK_1_5 and the created type is an annotation type, this IncorrectOperationException is thrown. Annotations were introduced in Java 5, so writing '@interface' into a source root configured for 1.4 or lower is rejected before the file is added.","triggerScenarios":"Using a template that declares an @interface while the module/directory language level is JDK_1_4 or lower (e.g. legacy project, module set explicitly to 1.4, or a source root inheriting an old project level).","commonSituations":"Old projects never migrated past pre-5 language levels; modules whose language level was pinned for old build tooling; SDK or Maven/Gradle import setting a low source compatibility that maps to a low language level.","solutions":["Raise the language level: File | Project Structure | Modules -> Sources tab -> Language Level, or set maven-compiler-plugin source/target (or Gradle sourceCompatibility) to 1.5+ and re-import.","Or choose a template without an annotation type (plain class/interface) if the code must stay at the old level.","After changing build config, re-import the project so the IDE language level updates."],"exampleFix":"<!-- before (pom.xml) -->\n<maven-compiler-plugin><configuration><source>1.4</source></configuration></maven-compiler-plugin>\n\n<!-- after -->\n<maven-compiler-plugin><configuration><source>1.8</source><target>1.8</target></configuration></maven-compiler-plugin>","handlingStrategy":"validation","validationCode":"// Before creating from an annotation-type template:\nLanguageLevel ll = JavaDirectoryService.getInstance().getLanguageLevel(directory);\nif (ll.isLessThan(LanguageLevel.JDK_1_5) && templateDeclaresAnnotationType) {\n  Messages.showWarningDialog(\"Raise the module language level to 1.5+ to create @interface files\", \"Language Level Too Low\");\n  return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set module language level to at least 1.5 before using annotation templates","Keep build-tool source levels in sync with IDE language levels"],"tags":["java","language-level","file-templates","annotations","project-configuration"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}