{"record":{"id":"6a00a2e5be376cad","repo":"alibaba/nacos","slug":"getdescription-cannot-be-resolved-in-the-file-6a00a2","errorCode":null,"errorMessage":"{getDescription()} cannot be resolved in the file system for checking its last-modified timestamp","messagePattern":"(.+?) cannot be resolved in the file system for checking its last-modified timestamp","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractFileResolvingResource.java","lineNumber":267,"sourceCode":"        if (ResourceUtils.isFileUrl(url) || ResourceUtils.isJarUrl(url)) {\n            // Proceed with file system resolution\n            fileCheck = true;\n            try {\n                File fileToCheck = getFileForLastModifiedCheck();\n                long lastModified = fileToCheck.lastModified();\n                if (lastModified > 0L || fileToCheck.exists()) {\n                    return lastModified;\n                }\n            } catch (FileNotFoundException ex) {\n                // Defensively fall back to URL connection check instead\n            }\n        }\n        // Try a URL connection last-modified header\n        URLConnection con = url.openConnection();\n        customizeConnection(con);\n        long lastModified = con.getLastModified();\n        if (fileCheck && lastModified == 0 && con.getContentLengthLong() <= 0) {\n            throw new FileNotFoundException(getDescription()\n                    + \" cannot be resolved in the file system for checking its last-modified timestamp\");\n        }\n        return lastModified;\n    }\n\n    /**\n     * Customize the given {@link URLConnection}, obtained in the course of an\n     * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.\n     * Calls {@link ResourceUtils#useCachesIfNecessary(URLConnection)} and\n     * delegates to {@link #customizeConnection(HttpURLConnection)} if possible.\n     * Can be overridden in subclasses.\n     *\n     * @param con the URLConnection to customize\n     * @throws IOException if thrown from URLConnection methods\n     */\n    protected void customizeConnection(URLConnection con) throws IOException {\n        ResourceUtils.useCachesIfNecessary(con);\n        if (con instanceof HttpURLConnection) {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractFileResolvingResource.java#L249-L285","documentation":"Thrown by AbstractFileResolvingResource.lastModified() in its fallback path: when fileCheck is true, the URL connection reports lastModified 0 and content length <= 0, meaning neither the file system nor the URL connection could find the resource. FileNotFoundException indicates the resource is effectively missing on both fronts.","triggerScenarios":"Calling resource.lastModified() (often transitively via resource.exists() or freshness checks) where the resource is a missing file-backed URL and the URLConnection also yields no last-modified/length; scanning deleted classpath roots.","commonSituations":"Deleted/rotated log or config file whose resource handle is still cached; hot-reload watching a file that was removed; URLConnection to a removed remote resource returning empty headers; stale resource reference after redeploy.","solutions":["Check resource.exists() before relying on lastModified().","Refresh/resolve the resource handle anew before each timestamp check rather than caching it.","Handle FileNotFoundException around lastModified() and treat it as 'resource removed'.","For watch loops, recreate the Resource from the current path on each cycle."],"exampleFix":"// before\nlong ts = resource.lastModified(); // throws when both file & URLConnection empty\n\n// after\nlong ts;\ntry {\n    ts = resource.lastModified();\n} catch (FileNotFoundException e) {\n    ts = -1L; // treat as missing\n}","handlingStrategy":"validation","validationCode":"if (!resource.exists()) {\n    return -1L; // treat as missing\n}\nreturn resource.lastModified();","typeGuard":"boolean hasLastModified(Resource r) {\n    try { return r.exists() && r.lastModified() > 0L; }\n    catch (IOException e) { return false; }\n}","tryCatchPattern":"try {\n    long ts = resource.lastModified();\n} catch (FileNotFoundException e) {\n    log.debug(\"Resource gone for lastModified: {}\", e.getMessage());\n    ts = -1L;\n}","preventionTips":["Check exists() before relying on lastModified().","Re-resolve the resource from its path each cycle in watch loops.","Treat FileNotFoundException from lastModified as 'resource removed'."],"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"}