{"record":{"id":"1a74fa495fb5e783","repo":"JetBrains/intellij-community","slug":"file-name-must-end-with","errorCode":null,"errorMessage":"File name must end with .","messagePattern":"File name must end with \\.","errorType":"exception","errorClass":"IncorrectOperationException","httpStatus":null,"severity":"error","filePath":"java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiSnippetAttributeValueImpl.java","lineNumber":234,"sourceCode":"\n    @Override\n    public PsiElement handleElementRename(@NotNull String newElementName) throws IncorrectOperationException {\n      // TODO\n      return null;\n    }\n\n    @Override\n    public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {\n      if (!(element instanceof PsiFile)) throw new IncorrectOperationException(\"PsiFile expected\");\n      if (isReferenceTo(element)) return PsiSnippetAttributeValueImpl.this;\n      VirtualFile virtualFile = ((PsiFile)element).getVirtualFile();\n      String relativePath = VfsUtilCore.getRelativePath(virtualFile, mySnippetRoot, '.');\n      if (relativePath == null) {\n        throw new IncorrectOperationException(\"File not in \" + mySnippetRoot + \": \" + virtualFile);\n      }\n      if (myExtension != null) {\n        if (!StringUtil.endsWithIgnoreCase(relativePath, \".\" + myExtension)) {\n          throw new IncorrectOperationException(\"File name must end with .\" + myExtension + \": \" + virtualFile);\n        }\n        relativePath = relativePath.substring(0, relativePath.length() - myExtension.length() - 1);\n      }\n      String newText;\n      if (!relativePath.contains(mySeparator)) {\n        newText = relativePath;\n      }\n      else if (getText().startsWith(\"'\")) {\n        newText = \"'\" + relativePath + \"'\";\n      }\n      else {\n        newText = \"\\\"\" + relativePath + \"\\\"\";\n      }\n      ASTNode node = getNode();\n      LeafElement newNode = ChangeUtil.copyLeafWithText((LeafElement)node, newText);\n      node.getTreeParent().replaceChild(node, newNode);\n      return newNode.getPsi();\n    }","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiSnippetAttributeValueImpl.java#L216-L252","documentation":"For @snippet javadoc tags whose region/file attribute declares a required file extension (e.g. region files expected to be .java), bindToElement verifies the target file's relative path ends with that extension. If it does not, it throws IncorrectOperationException(\"File name must end with .<ext>: <file>\").","triggerScenarios":"Calling bindToElement on a snippet file reference that requires extension X (myExtension, e.g. \"java\") with a target PsiFile whose name does not end with .X — e.g. binding a .txt or .kts file to a reference declared for .java snippets.","commonSituations":"Move/rename refactorings that rebind snippet references to files of a different type; mixing languages in snippet directories (java snippets vs properties files); manual edits of the @snippet attribute followed by IDE refactors.","solutions":["Bind only to files with the expected extension: check virtualFile.getName().endsWith(\".\" + expectedExt) first.","If you intentionally changed the snippet language, update or remove the extension constraint in the @snippet attribute before rebinding.","Keep one snippet directory per language so refactors cannot cross-bind mismatched types."],"exampleFix":"// before\nsnippetAttrRef.bindToElement(txtFile); // reference expects .java -> throws\n\n// after\nif (virtualFile.getName().endsWith(\".\" + expectedExtension)) {\n  snippetAttrRef.bindToElement(txtFile);\n} else {\n  // pick a matching .java snippet or adjust the @snippet attribute\n}","handlingStrategy":"validation","validationCode":"if (!vf.getName().endsWith(\".\" + expectedExtension)) return; // extension mismatch","typeGuard":null,"tryCatchPattern":"try { snippetRef.bindToElement(f); } catch (IncorrectOperationException e) { /* pick file with matching extension */ }","preventionTips":["One snippet directory per language/extension.","Check the required extension from the @snippet attribute before binding."],"tags":["java","psi","javadoc","snippets","file-extension","bind"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}