perwendel/spark · error · java.io.FileNotFoundException
cannot be resolved to absolute file path because it does…
Error message
${description} cannot be resolved to absolute file path because it does not reside in the file system: ${resourceUri} What it means
ResourceUtils.getFile(URI, String) is the URI variant of the file-system resolver: it converts a URI to a java.io.File only if the URI scheme is 'file'. Any other scheme (jar, http, wsjar, etc.) triggers FileNotFoundException because there is no absolute file path for the resource.
Solutions
- Verify uri.getScheme() equals "file" before invoking getFile.
- For jar-packaged resources use stream access (openStream) instead of File.
- Unpack jar resources to a temporary file when a physical File is mandatory.
- Normalize container-specific schemes (wsjar, vfs) to extract the inner file: part before conversion.
Example fix
// before
File f = ResourceUtils.getFile(uri, "config");
// after
if (uri.getScheme() == null || !uri.getScheme().equals("file")) {
try (InputStream in = uri.toURL().openStream()) { /* read stream */ }
} else {
File f = ResourceUtils.getFile(uri, "config");
} Defensive patterns
Strategy: type-guard
Validate before calling
if (uri == null || !"file".equals(uri.getScheme()))
throw new IllegalArgumentException("Not a file-system URI: " + uri); Type guard
boolean isFileUri(URI u) { return u != null && "file".equals(u.getScheme()); } Try / catch
try {
File f = ResourceUtils.getFile(uri, "config");
} catch (FileNotFoundException e) {
try (InputStream in = uri.toURL().openStream()) { /* stream fallback */ }
} Prevention
- Check URI scheme before conversion; handle jar:/wsjar:/vfs: explicitly.
- Use stream-based access for classpath resources.
- Test in fat-jar deployments where schemes differ from exploded classpaths.
- Normalize container-specific schemes to file: where possible.
When it happens
Trigger: Calling ResourceUtils.getFile(uri, description) with a URI whose getScheme() is not 'file' — typically a URI derived from a jar-packaged classpath resource or a remote URL.
Common situations: Packaging the app into a jar/fat jar so classpath URIs become jar: scheme; passing web URLs by mistake; container servers rewriting file: to wsjar:/vfs: schemes (WebLogic, JBoss).
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- class path resource [ ] cannot be resolved to URL because…
- cannot be resolved to absolute file path because it does…
- cannot be resolved to absolute file path because it does…
- Bad URI % encoding
AI-assisted analysis of perwendel/spark@1973e402f5 (2026-09-10).
Data as JSON: /api/errors/63e4b68872fa1371.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/spark/utils/ResourceUtils.java:253
public static File getFile(URI resourceUri) throws FileNotFoundException {
return getFile(resourceUri, "URI");
}
/**
* Resolve the given resource URI to a {@code java.io.File},
* i.e. to a file in the file system.
*
* @param resourceUri the resource URI to resolve
* @param description a description of the original resource that
* the URI was created for (for example, a class path location)
* @return a corresponding File object
* @throws FileNotFoundException if the URL cannot be resolved to
* a file in the file system
*/
public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
Assert.notNull(resourceUri, "Resource URI must not be null");
if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) {
throw new FileNotFoundException(
description + " cannot be resolved to absolute file path " +
"because it does not reside in the file system: " + resourceUri
);
}
return new File(resourceUri.getSchemeSpecificPart());
}
/**
* Determine whether the given URL points to a resource in the file system,
* that is, has protocol "file" or "vfs".
*
* @param url the URL to check
* @return whether the URL has been identified as a file system URL
*/
public static boolean isFileURL(URL url) {
String protocol = url.getProtocol();
return (URL_PROTOCOL_FILE.equals(protocol));
}View on GitHub (pinned to 1973e402f5)