{"record":{"id":"c0f7bb78f1ba7210","repo":"alibaba/nacos","slug":"getdescription-cannot-be-resolved-to-absolute","errorCode":null,"errorMessage":"{getDescription()} cannot be resolved to absolute file path","messagePattern":"(.+?) cannot be resolved to absolute file path","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractResource.java","lineNumber":134,"sourceCode":"     * by {@link #getUrl()}.\n     */\n    @Override\n    public URI getUri() throws IOException {\n        URL url = getUrl();\n        try {\n            return ResourceUtils.toUri(url);\n        } catch (URISyntaxException ex) {\n            throw new NestedIoException(\"Invalid URI [\" + url + \"]\", ex);\n        }\n    }\n\n    /**\n     * This implementation throws a FileNotFoundException, assuming\n     * that the resource cannot be resolved to an absolute file path.\n     */\n    @Override\n    public File getFile() throws IOException {\n        throw new FileNotFoundException(getDescription() + \" cannot be resolved to absolute file path\");\n    }\n\n    /**\n     * This implementation returns {@link Channels#newChannel(InputStream)}\n     * with the result of {@link #getInputStream()}.\n     * This is the same as in {@link Resource}'s corresponding default method\n     * but mirrored here for efficient JVM-level dispatching in a class hierarchy.\n     */\n    @Override\n    public ReadableByteChannel readableChannel() throws IOException {\n        return Channels.newChannel(getInputStream());\n    }\n\n    /**\n     * This method reads the entire InputStream to determine the content length.\n     * For a custom sub-class of {@code InputStreamResource}, we strongly\n     * recommend overriding this method with a more optimal implementation, e.g.\n     * checking File length, or possibly simply returning -1 if the stream can","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractResource.java#L116-L152","documentation":"Default AbstractResource.getFile() throws FileNotFoundException when a concrete subclass has not overridden getFile() to return a java.io.File. It is the base fallback: resources that are not file-backed cannot be resolved to an absolute file path. Hit when code calls getFile() on a non-file resource (e.g. a classpath-in-jar or URL resource).","triggerScenarios":"Calling resource.getFile() on an AbstractResource subclass that only provides getInputStream/getUrl; resolving a classpath resource that lives inside a jar to a File; a custom resource with no file representation.","commonSituations":"Classpath resource packaged in a jar (getFile() cannot return a real File for a jar entry); URL/byte-array resources passed to code expecting a File; tests stubbing AbstractResource without overriding getFile().","solutions":["Use getInputStream() instead of getFile() for non-file-backed resources (works inside jars).","If you truly need a File, copy the stream to a temp file via Files.copy(in, tmp).","Override getFile() in your subclass to return a real File when the resource is file-backed.","Use ClassPathResource only when you know the resource is on the filesystem, not inside a jar."],"exampleFix":"// before\nFile f = resource.getFile(); // FileNotFoundException for jar classpath entry\n\n// after\nFile tmp = File.createTempFile(\"res\", \".tmp\");\ntry (InputStream in = resource.getInputStream()) {\n    Files.copy(in, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);\n}\nFile f = tmp;","handlingStrategy":"validation","validationCode":"File f;\ntry {\n    f = resource.getFile();\n} catch (FileNotFoundException e) {\n    // not file-backed; stream to a temp file if a File is truly required\n    f = Files.createTempFile(\"res\", \".tmp\").toFile();\n    try (InputStream in = resource.getInputStream()) {\n        Files.copy(in, f.toPath(), StandardCopyOption.REPLACE_EXISTING);\n    }\n}","typeGuard":"boolean isFileBacked(Resource r) {\n    try { return r.getFile() != null; }\n    catch (IOException e) { return false; }\n}","tryCatchPattern":"try {\n    File f = resource.getFile();\n} catch (FileNotFoundException e) {\n    log.debug(\"Resource not file-backed, using stream\");\n}","preventionTips":["Use getInputStream() for resources that may be inside jars.","Override getFile() in custom resources that are genuinely file-backed.","Avoid assuming classpath resources are files."],"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"}