{"record":{"id":"a48eb7c3fbb946ed","repo":"alibaba/spring-ai-alibaba","slug":"cannot-convert-resource-to-file-system-path-a48eb7","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/skills/registry/filesystem/FileSystemSkillRegistry.java","lineNumber":362,"sourceCode":"\t\t/**\n\t\t * Sets the user skills directory from a Spring Resource.\n\t\t * <p><b>Optional</b>: If not set, defaults to <code>~/saa/skills</code>\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 * Sets the project skills directory path.\n\t\t * <p><b>Optional</b>: If not set, defaults to <code>./skills</code>\n\t\t * (current working directory with \"skills\" subdirectory).\n\t\t *\n\t\t * @param directory the directory path for project-level skills\n\t\t * @return this builder\n\t\t */\n\t\tpublic Builder projectSkillsDirectory(String directory) {\n\t\t\tthis.projectSkillsDirectory = directory;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/skills/registry/filesystem/FileSystemSkillRegistry.java#L344-L380","documentation":"The builder's userSkillsDirectory(Resource) method resolves the Spring Resource to an absolute filesystem path via resource.getFile(); if the resource cannot be converted (e.g. it is not file-backed, like a jar/classpath resource without a file), the thrown IOException is wrapped in IllegalArgumentException.","triggerScenarios":"Passing a ClassPathResource pointing inside a packaged JAR, a resource from a remote/protocol handler, or any Resource whose getFile() throws IOException because no physical file backs it.","commonSituations":"Packaging skills as resources inside a Spring Boot fat JAR and then calling userSkillsDirectory(resource) — jar-embedded resources have no File representation; using a wrong resource URL prefix.","solutions":["Ensure skills live in an exploded directory on the filesystem, not inside a JAR","Use a Resource that is file-backed (FileSystemResource or an exploded classpath folder)","Catch IllegalArgumentException and fall back to a directory path String overload"],"exampleFix":"// before\nregistry.builder().userSkillsDirectory(new ClassPathResource(\"skills/\"));\n// after\nPath dir = Path.of(\"config/skills\");\nregistry.builder().userSkillsDirectory(dir.toString());","handlingStrategy":"validation","validationCode":"Resource r = new ClassPathResource(\"skills/\"); if (!\"file\".equals(r.getURL().getProtocol())) { /* not file-backed; use a path instead */ }","typeGuard":"boolean isFileBacked(Resource r) throws IOException { return r.getFile().isDirectory(); }","tryCatchPattern":"try { builder.userSkillsDirectory(resource); } catch (IllegalArgumentException e) { builder.userSkillsDirectory(extractedDirPath); }","preventionTips":["Never point the registry at resources inside JARs","Prefer plain filesystem path overloads","Extract embedded resources to disk at startup if needed"],"tags":["java","spring","resource","filesystem"],"backgroundTag":"invalid-argument-value","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"}