{"record":{"id":"3483c54539e750e7","repo":"alibaba/spring-ai-alibaba","slug":"cannot-convert-resource-to-file-system-path","errorCode":null,"errorMessage":"Cannot convert resource to file system path: ","messagePattern":"Cannot convert resource to file system path: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/advisors/SkillPromptAugmentAdvisor.java","lineNumber":283,"sourceCode":"\t\t/**\n\t\t * Set the user skills directory from a Spring Resource.\n\t\t * <p><b>Optional</b>: Defaults to <code>~/saa/skills</code> if not specified.\n\t\t * <p>The Resource will be converted to a file system path. If the resource cannot be\n\t\t * resolved to a file (e.g., it's inside a JAR), an IllegalArgumentException will be thrown.\n\t\t *\n\t\t * @param resource the Resource pointing to the user-level skills directory\n\t\t * @return this builder\n\t\t * @throws IllegalArgumentException if the resource cannot be converted to a file system path\n\t\t */\n\t\tpublic Builder userSkillsDirectory(Resource resource) {\n\t\t\ttry {\n\t\t\t\tif (resource != null && resource.exists()) {\n\t\t\t\t\tFile file = resource.getFile();\n\t\t\t\t\tthis.userSkillsDirectory = file.getAbsolutePath();\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tthrow new IllegalArgumentException(\"Cannot convert resource to file system path: \" + resource, e);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Set the project skills directory.\n\t\t * <p><b>Optional</b>: Defaults to <code>classpath:skills</code> or <code>./skills</code> if not specified.\n\t\t *\n\t\t * @param projectSkillsDirectory the project skills directory path\n\t\t * @return this builder\n\t\t */\n\t\tpublic Builder projectSkillsDirectory(String projectSkillsDirectory) {\n\t\t\tthis.projectSkillsDirectory = projectSkillsDirectory;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Set the project skills directory from a Spring Resource.","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/advisors/SkillPromptAugmentAdvisor.java#L265-L301","documentation":"SkillPromptAugmentAdvisor.Builder.userSkillsDirectory accepts a Spring Resource; to use it as a skills directory it must resolve to a real file-system path via resource.getFile(). When the resource cannot be converted (e.g. classpath or URL resource without a backing file), the IOException is rethrown as IllegalArgumentException.","triggerScenarios":"Calling .userSkillsDirectory(new ClassPathResource(\"skills\")) or any Resource backed by a jar/URL rather than the file system, so Resource.getFile() throws FileNotFoundException (an IOException).","commonSituations":"App packaged as a fat jar where classpath resources live inside the archive; using ResourceLoader-provided resources like classpath: or https: URLs; pointing the builder at a non-existent resource that still passes through the catch on getFile().","solutions":["Use a FileSystemResource or a plain String directory path pointing to an exploded on-disk directory","Unpack classpath skills to a temp directory at startup (e.g. FileSystemResource of Path) before passing it","Check resource.getURI() scheme: only 'file:' resources support getFile()","Ensure the directory exists and the application has read access before building the advisor"],"exampleFix":"// before\nbuilder.userSkillsDirectory(new ClassPathResource(\"skills\"));\n// after\nPath dir = Path.of(System.getProperty(\"user.home\"), \".myapp\", \"skills\");\nFiles.createDirectories(dir);\nbuilder.userSkillsDirectory(new FileSystemResource(dir.toFile()));","handlingStrategy":"validation","validationCode":"Resource r = ...;\nif (!\"file\".equals(r.getURI().getScheme()) || !r.exists())\n    throw new IllegalArgumentException(\"userSkillsDirectory must be an existing file-system directory\");","typeGuard":"static boolean isFileSystemResource(Resource r) {\n    try { return r.exists() && \"file\".equals(r.getURI().getScheme()); }\n    catch (IOException e) { return false; }\n}","tryCatchPattern":"try { builder.userSkillsDirectory(res); } catch (IllegalArgumentException e) { log.error(\"resolve skills dir to a real path\", e); }","preventionTips":["Only pass FileSystemResource (or string paths) to skills-directory setters","Unpack classpath resources from jars at startup before use","Verify the directory exists on disk in the deployment environment"],"tags":["spring","resource","filesystem"],"backgroundTag":"file-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}