{"record":{"id":"63e4b68872fa1371","repo":"perwendel/spark","slug":"description-cannot-be-resolved-to-absolute-file-63e4b6","errorCode":null,"errorMessage":"${description} cannot be resolved to absolute file path because it does not reside in the file system: ${resourceUri}","messagePattern":"(.+?) cannot be resolved to absolute file path because it does not reside in the file system: (.+?)","errorType":"exception","errorClass":"java.io.FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/main/java/spark/utils/ResourceUtils.java","lineNumber":253,"sourceCode":"    public static File getFile(URI resourceUri) throws FileNotFoundException {\n        return getFile(resourceUri, \"URI\");\n    }\n\n    /**\n     * Resolve the given resource URI to a {@code java.io.File},\n     * i.e. to a file in the file system.\n     *\n     * @param resourceUri the resource URI to resolve\n     * @param description a description of the original resource that\n     *                    the URI was created for (for example, a class path location)\n     * @return a corresponding File object\n     * @throws FileNotFoundException if the URL cannot be resolved to\n     *                               a file in the file system\n     */\n    public static File getFile(URI resourceUri, String description) throws FileNotFoundException {\n        Assert.notNull(resourceUri, \"Resource URI must not be null\");\n        if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) {\n            throw new FileNotFoundException(\n                    description + \" cannot be resolved to absolute file path \" +\n                            \"because it does not reside in the file system: \" + resourceUri\n            );\n        }\n        return new File(resourceUri.getSchemeSpecificPart());\n    }\n\n    /**\n     * Determine whether the given URL points to a resource in the file system,\n     * that is, has protocol \"file\" or \"vfs\".\n     *\n     * @param url the URL to check\n     * @return whether the URL has been identified as a file system URL\n     */\n    public static boolean isFileURL(URL url) {\n        String protocol = url.getProtocol();\n        return (URL_PROTOCOL_FILE.equals(protocol));\n    }","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/perwendel/spark/blob/1973e402f5d4c1442ad34a1d38ed0758079f7773/src/main/java/spark/utils/ResourceUtils.java#L235-L271","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nFile f = ResourceUtils.getFile(uri, \"config\");\n// after\nif (uri.getScheme() == null || !uri.getScheme().equals(\"file\")) {\n    try (InputStream in = uri.toURL().openStream()) { /* read stream */ }\n} else {\n    File f = ResourceUtils.getFile(uri, \"config\");\n}","handlingStrategy":"type-guard","validationCode":"if (uri == null || !\"file\".equals(uri.getScheme()))\n    throw new IllegalArgumentException(\"Not a file-system URI: \" + uri);","typeGuard":"boolean isFileUri(URI u) { return u != null && \"file\".equals(u.getScheme()); }","tryCatchPattern":"try {\n    File f = ResourceUtils.getFile(uri, \"config\");\n} catch (FileNotFoundException e) {\n    try (InputStream in = uri.toURL().openStream()) { /* stream fallback */ }\n}","preventionTips":["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."],"tags":["file-not-found","uri","classpath"],"backgroundTag":"file-not-found","analyzedSha":"1973e402f5d4c1442ad34a1d38ed0758079f7773","analyzedAt":"2026-09-10T14:38:22.866Z","contentChangedAt":"2026-09-10T14:38:22.866Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}