{"record":{"id":"82006d800b92557c","repo":"JetBrains/intellij-community","slug":"0-is-not-an-identifier","errorCode":null,"errorMessage":"''{0}'' is not an identifier.","messagePattern":"''(.+?)'' is not an identifier\\.","errorType":"validation","errorClass":"IncorrectOperationException","httpStatus":null,"severity":"error","filePath":"java/java-psi-api/src/com/intellij/psi/util/PsiUtil.java","lineNumber":1115,"sourceCode":"    if (substitutionMap == null) return null;\n    PsiElementFactory factory = JavaPsiFacade.getElementFactory(aClass.getProject());\n    return factory.createType(aClass, factory.createSubstitutor(substitutionMap));\n  }\n\n  public static boolean isInsideJavadocComment(PsiElement element) {\n    return PsiTreeUtil.getParentOfType(element, PsiDocComment.class, true, PsiMember.class) != null;\n  }\n\n  public static @NotNull @Unmodifiable List<PsiTypeElement> getParameterTypeElements(@NotNull PsiParameter parameter) {\n    PsiTypeElement typeElement = parameter.getTypeElement();\n    return typeElement != null && typeElement.getType() instanceof PsiDisjunctionType\n           ? PsiTreeUtil.getChildrenOfTypeAsList(typeElement, PsiTypeElement.class)\n           : Collections.singletonList(typeElement);\n  }\n\n  public static void checkIsIdentifier(@NotNull PsiManager manager, String text) throws IncorrectOperationException{\n    if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(text)){\n      throw new IncorrectOperationException(JavaPsiBundle.message(\"0.is.not.an.identifier\", text) );\n    }\n  }\n\n  public static @Nullable VirtualFile getJarFile(@NotNull PsiElement candidate) {\n    VirtualFile file = candidate.getContainingFile().getVirtualFile();\n    if (file != null && file.getFileSystem().getProtocol().equals(\"jar\")) {\n      return VfsUtilCore.getVirtualFileForJar(file);\n    }\n    return file;\n  }\n\n  public static boolean isAnnotationMethod(PsiElement element) {\n    if (!(element instanceof PsiAnnotationMethod)) return false;\n    PsiClass psiClass = ((PsiAnnotationMethod)element).getContainingClass();\n    return psiClass != null && psiClass.isAnnotationType();\n  }\n\n  /**","sourceCodeStart":1097,"sourceCodeEnd":1133,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-psi-api/src/com/intellij/psi/util/PsiUtil.java#L1097-L1133","documentation":"Thrown by PsiUtil.checkIsIdentifier when the given text is not a valid Java identifier according to PsiNameHelper (e.g. it contains spaces, dots, operators, or is a keyword). It is a guard used by PSI rename and element-factory code paths that must produce syntactically valid names. The throw is an IncorrectOperationException signaling the caller supplied an unusable name.","triggerScenarios":"Calling PsiUtil.checkIsIdentifier(manager, text) directly, or any PSI setName/createElementFromText flow that routes through it, with text like \"my class\", \"foo.bar\", \"int\", \"\", or a name with illegal characters.","commonSituations":"Refactoring plugins or rename handlers that pass a user-typed or generated string straight into PsiElement.setName; live templates or code generators producing names with whitespace; programmatic element creation from unvalidated input.","solutions":["Validate the name first with PsiNameHelper.getInstance(project).isIdentifier(name) and reject or sanitize it before calling setName.","If the name comes from user input, show an input validator (e.g. Messages.showInputDialog with a validator) that only accepts identifiers.","Strip illegal characters or convert the string with Java convention (e.g. NameUtil or Introspector.decapitalize on a sanitized base) before use.","If the element legitimately has a non-identifier name (keyword or operator overloading in other JVM languages), avoid this API for that element type."],"exampleFix":"// before\npsiVariable.setName(userInput); // throws when userInput = \"my value\"\n\n// after\nPsiNameHelper helper = PsiNameHelper.getInstance(project);\nif (!helper.isIdentifier(userInput)) {\n  userInput = sanitizeToIdentifier(userInput); // strip/space->camel yourself\n}\npsiVariable.setName(userInput);","handlingStrategy":"validation","validationCode":"PsiNameHelper helper = PsiNameHelper.getInstance(project);\nif (!helper.isIdentifier(newName)) {\n  // reject or sanitize before any setName call\n  return;\n}","typeGuard":"static boolean isValidIdentifier(Project p, String s) {\n  return s != null && PsiNameHelper.getInstance(p).isIdentifier(s);\n}","tryCatchPattern":"try { psiElement.setName(name); } catch (IncorrectOperationException e) { /* report invalid name to user */ }","preventionTips":["Always run PsiNameHelper.isIdentifier on user-supplied names before PSI mutation.","Use input dialogs with identifier validators for rename UIs.","Never feed strings containing whitespace, dots, or keywords into setName."],"tags":["java","psi","validation","rename"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}