alibaba/nacos · error · FileNotFoundException
{getDescription()} cannot be resolved in the file system for
Error message
{getDescription()} cannot be resolved in the file system for checking its last-modified timestamp What it means
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.
Source
Thrown at common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractFileResolvingResource.java:267
if (ResourceUtils.isFileUrl(url) || ResourceUtils.isJarUrl(url)) {
// Proceed with file system resolution
fileCheck = true;
try {
File fileToCheck = getFileForLastModifiedCheck();
long lastModified = fileToCheck.lastModified();
if (lastModified > 0L || fileToCheck.exists()) {
return lastModified;
}
} catch (FileNotFoundException ex) {
// Defensively fall back to URL connection check instead
}
}
// Try a URL connection last-modified header
URLConnection con = url.openConnection();
customizeConnection(con);
long lastModified = con.getLastModified();
if (fileCheck && lastModified == 0 && con.getContentLengthLong() <= 0) {
throw new FileNotFoundException(getDescription()
+ " cannot be resolved in the file system for checking its last-modified timestamp");
}
return lastModified;
}
/**
* Customize the given {@link URLConnection}, obtained in the course of an
* {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
* Calls {@link ResourceUtils#useCachesIfNecessary(URLConnection)} and
* delegates to {@link #customizeConnection(HttpURLConnection)} if possible.
* Can be overridden in subclasses.
*
* @param con the URLConnection to customize
* @throws IOException if thrown from URLConnection methods
*/
protected void customizeConnection(URLConnection con) throws IOException {
ResourceUtils.useCachesIfNecessary(con);
if (con instanceof HttpURLConnection) {View on GitHub (pinned to 9b989acdf1)
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.
Example fix
// before
long ts = resource.lastModified(); // throws when both file & URLConnection empty
// after
long ts;
try {
ts = resource.lastModified();
} catch (FileNotFoundException e) {
ts = -1L; // treat as missing
} Defensive patterns
Strategy: validation
Validate before calling
if (!resource.exists()) {
return -1L; // treat as missing
}
return resource.lastModified(); Type guard
boolean hasLastModified(Resource r) {
try { return r.exists() && r.lastModified() > 0L; }
catch (IOException e) { return false; }
} Try / catch
try {
long ts = resource.lastModified();
} catch (FileNotFoundException e) {
log.debug("Resource gone for lastModified: {}", e.getMessage());
ts = -1L;
} Prevention
- 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'.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {getDescription()} cannot be resolved in the file system for
- {getDescription()} cannot be resolved to absolute file path
- {getDescription()} cannot be resolved in the file system for
- Cannot create a relative resource for {getDescription()}
- {getDescription()} cannot be opened because it does not exis
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/6a00a2e5be376cad.
Report an issue: GitHub.