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 content length What it means
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.
Source
Thrown at common/src/main/java/com/alibaba/nacos/common/packagescan/resource/AbstractFileResolvingResource.java:233
public ReadableByteChannel readableChannel() throws IOException {
try {
// Try file system channel
return FileChannel.open(getFile().toPath(), StandardOpenOption.READ);
} catch (FileNotFoundException | NoSuchFileException ex) {
// Fall back to InputStream adaptation in superclass
return super.readableChannel();
}
}
@Override
public long contentLength() throws IOException {
URL url = getUrl();
if (ResourceUtils.isFileUrl(url)) {
// Proceed with file system resolution
File file = getFile();
long length = file.length();
if (length == 0L && !file.exists()) {
throw new FileNotFoundException(getDescription()
+ " cannot be resolved in the file system for checking its content length");
}
return length;
} else {
// Try a URL connection content-length header
URLConnection con = url.openConnection();
customizeConnection(con);
return con.getContentLengthLong();
}
}
@Override
public long lastModified() throws IOException {
URL url = getUrl();
boolean fileCheck = false;
if (ResourceUtils.isFileUrl(url) || ResourceUtils.isJarUrl(url)) {
// Proceed with file system resolution
fileCheck = true;View on GitHub (pinned to 9b989acdf1)
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.
Example fix
// before
long len = resource.contentLength(); // throws if file vanished
// after
File f = resource.getFile();
if (f.isFile()) {
long len = f.length();
} else {
try (InputStream in = resource.getInputStream()) {
long len = in.readAllBytes().length;
}
} Defensive patterns
Strategy: validation
Validate before calling
File f = resource.getFile();
if (!f.isFile()) {
throw new FileNotFoundException("resource not on disk: " + f);
}
long len = resource.contentLength(); Type guard
boolean isResolvableFile(Resource r) {
try { return r.getFile().isFile(); }
catch (IOException e) { return false; }
} Try / catch
try {
long len = resource.contentLength();
} catch (FileNotFoundException e) {
log.warn("Resource missing on disk, falling back to stream: {}", e.getMessage());
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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/5b211cfb97926d26.
Report an issue: GitHub.