{"record":{"id":"902c511688b8c0b8","repo":"JetBrains/intellij-community","slug":"file-not-in","errorCode":null,"errorMessage":"File not in ","messagePattern":"File not in ","errorType":"exception","errorClass":"IncorrectOperationException","httpStatus":null,"severity":"error","filePath":"java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiSnippetAttributeValueImpl.java","lineNumber":230,"sourceCode":"    public ResolveResult @NotNull [] multiResolve(boolean incompleteCode) {\n      PsiElement element = resolve();\n      return element == null ? ResolveResult.EMPTY_ARRAY : PsiElementResolveResult.createResults(element);\n    }\n\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();","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiSnippetAttributeValueImpl.java#L212-L248","documentation":"PsiSnippetAttributeValueImpl models the file attribute of an @snippet javadoc tag (JDK 18+ inline snippets), where external snippet files are addressed relative to a snippet root package. bindToElement computes a dot-separated relative path from the snippet root; if the target file is not under that root, getRelativePath returns null and it throws IncorrectOperationException(\"File not in <root>: <file>\").","triggerScenarios":"Calling bindToElement on an @snippet file reference with a PsiFile located outside the configured snippet root (by default the package containing the javadoc's file, or the snippet-package root); e.g. moving a snippet file to another source root and rebinding the reference.","commonSituations":"Move refactorings of snippet files across source roots that are not snippet roots; projects with multiple source roots where the snippet lives in a non-resource root; misconfigured 'snippet' packages.","solutions":["Keep referenced snippet files under the snippet root (same source root/package hierarchy as the javadoc file).","Before binding, verify VfsUtilCore.getRelativePath(file.getVirtualFile(), snippetRoot, '.') != null; if null, copy or move the file into the root first.","When the IDE move refactoring refuses, move the snippet file manually into the snippet root and update the attribute text."],"exampleFix":"// before\nsnippetAttrRef.bindToElement(targetPsiFile); // file outside snippet root -> throws\n\n// after\nVirtualFile vf = targetPsiFile.getVirtualFile();\nif (VfsUtilCore.getRelativePath(vf, snippetRoot, '.') == null) {\n  // move/copy the file under snippetRoot first, then bind\n} else {\n  snippetAttrRef.bindToElement(targetPsiFile);\n}","handlingStrategy":"validation","validationCode":"VirtualFile vf = targetFile.getVirtualFile();\nif (VfsUtilCore.getRelativePath(vf, snippetRoot, '.') == null) return; // outside snippet root","typeGuard":null,"tryCatchPattern":"try { snippetRef.bindToElement(f); } catch (IncorrectOperationException e) { /* move file into snippet root */ }","preventionTips":["Keep @snippet files inside the declared snippet root.","Verify relative path computability before rebinding snippet references."],"tags":["java","psi","javadoc","snippets","snippet-files","bind"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}