{"record":{"id":"149bf09c99aeffe3","repo":"alibaba/nacos","slug":"cannot-create-a-relative-resource-for-getdescript","errorCode":null,"errorMessage":"Cannot create a relative resource for {getDescription()}","messagePattern":"Cannot create a relative resource for (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractResource.java","lineNumber":216,"sourceCode":"     * Determine the File to use for timestamp checking.\n     * The default implementation delegates to {@link #getFile()}.\n     *\n     * @return the File to use for timestamp checking (never {@code null})\n     * @throws FileNotFoundException if the resource cannot be resolved as\n     *                               an absolute file path, i.e. is not available in a file system\n     * @throws IOException           in case of general resolution/reading failures\n     */\n    protected File getFileForLastModifiedCheck() throws IOException {\n        return getFile();\n    }\n\n    /**\n     * This implementation throws a FileNotFoundException, assuming\n     * that relative resources cannot be created for this resource.\n     */\n    @Override\n    public Resource createRelative(String relativePath) throws IOException {\n        throw new FileNotFoundException(\"Cannot create a relative resource for \" + getDescription());\n    }\n\n    /**\n     * This implementation always returns {@code null},\n     * assuming that this resource type does not have a filename.\n     */\n    @Override\n\n    public String getFilename() {\n        return null;\n    }\n\n\n    /**\n     * This implementation compares description strings.\n     *\n     * @see #getDescription()\n     */","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractResource.java#L198-L234","documentation":"Default AbstractResource.createRelative(String) throws FileNotFoundException because the base class cannot construct a relative resource. A concrete subclass (e.g. FileSystemResource, ClassPathResource) must override createRelative to define what 'relative to this resource' means. Hit when calling createRelative on a resource type that does not support relative paths.","triggerScenarios":"Calling resource.createRelative(\"child.json\") on a bare AbstractResource subclass or a custom resource that did not override createRelative; expecting relative resolution from a byte-array or opaque stream resource.","commonSituations":"Custom Resource wrapper used where framework code tries to resolve a sibling file; test stub of AbstractResource missing the override; passing an in-memory resource where a file-classpath sibling was expected.","solutions":["Override createRelative(String) in your subclass to compute the child path (e.g. resolve against getFilename()/getFile().getParent()).","Use a concrete resource that already implements createRelative (ClassPathResource, FileSystemResource, UrlResource).","Resolve the relative path yourself (against a known base) and create a new resource directly instead of via createRelative.","Avoid calling createRelative on opaque/in-memory resources."],"exampleFix":"// before\nclass BytesResource extends AbstractResource { /* only getInputStream */ }\nResource child = res.createRelative(\"next.json\"); // FileNotFoundException\n\n// after — use a file-backed resource that supports relative paths\nResource base = new FileSystemResource(\"/etc/app/config.json\");\nResource child = base.createRelative(\"next.json\");","handlingStrategy":"validation","validationCode":"try {\n    return resource.createRelative(relativePath);\n} catch (FileNotFoundException e) {\n    // resolve manually against a known base\n    return new FileSystemResource(baseDir.resolve(relativePath).toFile());\n}","typeGuard":"boolean supportsRelative(Resource r) {\n    // concrete file/url resources override createRelative; bare AbstractResource does not\n    return r instanceof FileSystemResource || r instanceof ClassPathResource\n        || r instanceof UrlResource;\n}","tryCatchPattern":"try {\n    Resource child = resource.createRelative(rel);\n} catch (FileNotFoundException e) {\n    log.debug(\"Resource does not support relative paths: {}\", e.getMessage());\n}","preventionTips":["Use concrete resource types (FileSystemResource, ClassPathResource, UrlResource) that implement createRelative.","Override createRelative in custom AbstractResource subclasses that need relative resolution.","Resolve relative paths against a known base rather than relying on opaque resources."],"tags":["resource","io","file","api-surface"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}