{"record":{"id":"5b211cfb97926d26","repo":"alibaba/nacos","slug":"getdescription-cannot-be-resolved-in-the-file","errorCode":null,"errorMessage":"{getDescription()} cannot be resolved in the file system for checking its content length","messagePattern":"(.+?) cannot be resolved in the file system for checking its content length","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractFileResolvingResource.java","lineNumber":233,"sourceCode":"    public ReadableByteChannel readableChannel() throws IOException {\n        try {\n            // Try file system channel\n            return FileChannel.open(getFile().toPath(), StandardOpenOption.READ);\n        } catch (FileNotFoundException | NoSuchFileException ex) {\n            // Fall back to InputStream adaptation in superclass\n            return super.readableChannel();\n        }\n    }\n\n    @Override\n    public long contentLength() throws IOException {\n        URL url = getUrl();\n        if (ResourceUtils.isFileUrl(url)) {\n            // Proceed with file system resolution\n            File file = getFile();\n            long length = file.length();\n            if (length == 0L && !file.exists()) {\n                throw new FileNotFoundException(getDescription()\n                        + \" cannot be resolved in the file system for checking its content length\");\n            }\n            return length;\n        } else {\n            // Try a URL connection content-length header\n            URLConnection con = url.openConnection();\n            customizeConnection(con);\n            return con.getContentLengthLong();\n        }\n    }\n\n    @Override\n    public long lastModified() throws IOException {\n        URL url = getUrl();\n        boolean fileCheck = false;\n        if (ResourceUtils.isFileUrl(url) || ResourceUtils.isJarUrl(url)) {\n            // Proceed with file system resolution\n            fileCheck = true;","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractFileResolvingResource.java#L215-L251","documentation":"Thrown by AbstractFileResolvingResource.contentLength() when the resource resolves to a file-system URL, the File reports length 0, and the file does not actually exist. FileNotFoundException signals the resource path pointed nowhere on disk. If the URL is not a file URL, a URLConnection content-length is used instead and this branch is skipped.","triggerScenarios":"Calling resource.contentLength() on a file:// (or a path resolved to File) whose target was deleted or never extracted; scanning resources where a listed class file is absent at runtime; a jar-extracted file path that no longer maps to disk.","commonSituations":"Deployed artifact references a file deleted during redeploy; a relative file resource resolved against a working directory that changed; classpath resource resolved to a file that is actually inside a jar (so getFile() returns a non-existent path); antivirus/quarantine removing a file after listing.","solutions":["Verify the file exists with Files.exists(Path) before calling contentLength().","For classpath resources that may live in jars, use getInputStream() rather than getFile()/contentLength() to avoid file-system resolution.","Fix the resource base path / working directory so resolution targets a real file.","Re-extract or redeploy the artifact so the referenced file is present."],"exampleFix":"// before\nlong len = resource.contentLength(); // throws if file vanished\n\n// after\nFile f = resource.getFile();\nif (f.isFile()) {\n    long len = f.length();\n} else {\n    try (InputStream in = resource.getInputStream()) {\n        long len = in.readAllBytes().length;\n    }\n}","handlingStrategy":"validation","validationCode":"File f = resource.getFile();\nif (!f.isFile()) {\n    throw new FileNotFoundException(\"resource not on disk: \" + f);\n}\nlong len = resource.contentLength();","typeGuard":"boolean isResolvableFile(Resource r) {\n    try { return r.getFile().isFile(); }\n    catch (IOException e) { return false; }\n}","tryCatchPattern":"try {\n    long len = resource.contentLength();\n} catch (FileNotFoundException e) {\n    log.warn(\"Resource missing on disk, falling back to stream: {}\", e.getMessage());\n}","preventionTips":["Prefer getInputStream() for classpath resources that may live in jars.","Verify Files.exists before contentLength().","Do not cache file resource handles across redeploy/delete boundaries."],"tags":["resource","io","file","classpath"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}